if (some_condition){ *custom_method = sub { do whatever you want }; }
(And arbitrary attributes an be added in p5 objects as well - but I don't have to show an example for that ;-)
This may be shocking if your background is primarily a C++ or Java one, but for perl hackers that's old news ;-)
Update for the monks who are not so familiar with Perl 6 object orientation:
In Perl 6 a class { stuff } directive runs stuff at compile time, "as the body of a method of the metaclass, which is responsible for interpreting the keywords of the class definition." (S12)
Why do we need meta classes? Well, perl 5 showed us that it's not very good to stick one object model - many programmer think it's not the best solution, and invent clever stuff like Moose to get around these limitations.
In Perl 6 you can just define your own meta classes if you don't like the default object model. That's why a class "declaration" is in fact just code that runs at compile time, and builds a class out of it.
In reply to Re: Perl 6 Shocking Revelations II - classes are built, not declared
by moritz
in thread Perl 6 Shocking Revelations II - classes are built, not declared
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |