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.
It is hard to part with ones modules sometimes, but in this case I am happy to see Class::Trait being taken to the next level with such capable hands.
Thanks Ovid