Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday November 26, 2005
06:45 PM

Runtime trait composition to the CPAN

[ #27748 ]

Soon Class::Trait 0.20 will be on the CPAN. We now have runtime trait composition and I'm just shy of 400 tests. The basic syntax works like this:

Class::Trait->apply($class_or_instance, @traits);

If you apply traits at runtime to a class, all instances (and subclasses) of that class get the new methods. If you apply traits to an instance, only that instance will get the new methods and the instance will be blessed into a new anonymous class.

In both cases, runtime trait application is similar to "mixins" whereby the trait methods will redefine (or override) any existing methods they find. When applying traits at compile time, existing methods take precedence and the trait's methods are silently discarded.

There are also some documentation updates, including a small section explaining when you would want to use traits.

There's a fair amount of ugly hackery to get Class::Trait->does to work and I have a bit of tramp data being passed around. Still, the test suite is fairly solid so I can revisit this later. Bug reports, of course, would be wonderful. Patches even more so.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.