If I understand your question correctly, then the following should make sense, otherwise... :-)
@ISA is used to locate attribute handlers, so there are a few ways to do this. The way the perldocs suggest (and the way I have always seen it) would be:
package MyAttrMaker;
use Attribute::Handlers;
sub UNIVERSAL::myattr :ATTR {
...
}
By putting the attribute into UNIVERSAL, the calling package will have it available in its @ISA tree. The downside to this is it is now available to all packages, regardless if they used MyAttrMaker.
To overcome this you could write:
package MyAttrMaker;
use Attribute::Handlers;
sub myattr :ATTR {
...
}
And then in your calling package use it like:
use MyAttrMaker;
use base MyAttrMaker;
Now it will only be available to packages that use is explicitly (or their sub-packages/sub-classes).
If you do not want to use base everytime you use the module, you could put the following import sub into your MyAttrMaker package:
sub import {
my $caller = caller;
push @{$caller . '::ISA'}, MyAttrMaker;
}
Now, all you have to say is use MyAttrMaker;.
None of these solutions are perfect, but they are the way to do it, and they don't cause too many problems. None of them solve your other requirement, that you can choose which attributes to import when using the module. I cannot think of an easy way to pull this off right now.
Ted |