Slash Boxes
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)

  (email not shown publicly)
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)

Wednesday November 16, 2005
10:50 PM

Ovid->does('World::Domination') if Class::Trait;

[ #27610 ]

My plans for world domination have taken another step towards fruition as Stevan Little has turned over maintenance of Class::Trait to me. At Kineticode, we need traits for a project we're working on but there were some subtle bugs lurking under the covers. I've been sending in changes to Class::Trait and Stevan thought it would be more efficient for me to just take over the module. The last major bug (that I know of) is this:

package SomeTrait;

use Class::Trait 'base';
use HTML::Entities 'encode_entities';

sub foo {...}

And in your code:

use Class::Trait 'SomeTrait';

Unfortunately, that's where things go wrong. Theoretically you should only get foo() in your namespace. However, encode_entities is also in your namespace. This is bad.

To fix this, you do this:

package SomeTrait;

use Class::Trait 'base';
our @PROVIDES = qw(foo);

use HTML::Entities 'encode_entities';

sub foo {...}

Now Class::Trait will check the @PROVIDES array to ensure that you're only getting what you should. It's not on the CPAN yet, though. I also have to make it work with composed traits. I finally figured out how to do that. The does() method (which you can now rename if you need to), will now return all traits that a class uses if you call it without arguments. Then I'll need to have the $trait->methods method search through all of those trait methods and pull their @PROVIDES arrays to get which methods should actually be exported. It turns out to be a lot harder than I thought, but Stevan has provided a good architecture and I'm slowly getting closer.

I will probably add attribute support soon so you can just declare a trait method as being "Public". For now I'm just trying to get the basic part done. Once this is fixed, I think Class::Trait will be ready for production.

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