zealot has asked for the wisdom of the Perl Monks concerning the following question:

I recently started experimenting with writing code that makes use of custom attributes. It occurred to me that attributes could be used to make a very elegant Exporter module.
package Foo; use base qw( ExporterAttributes ); my $PI : Export_Ok = 3.14; sub utility : Export_Ok Export_Group(general) {...} sub another : Export_Ok Export_Group(general) {...} 1; ... use Foo qw( :GENERAL ); utility($bar);
I started playing with this a bit, and found that the attribute specification would need to include the name to export the item as. Also, variables that are Exported should be readonly constants. That also seems to require some extra processing in my tests. So the above code would need to expand to the form:
package Foo; use base qw( ExporterAttributes ); use Readonly; my $PI : Export_Ok(PI); Readonly $PI => 3.14; sub utility : Export_Ok(utility) Export_Group(general) {...} sub another : Export_Ok(another) Export_Group(general) {...} 1;
Even with that extra overhead, this still would seem to be a nice method of exporting items from a package. Is this worth thinking about more, or is there something regarding how attributes are currently implemented that would make this less desirable. Daniel Risse

Replies are listed 'Best First'.
Re: Possible new module, Export using attributes
by venk (Acolyte) on Dec 22, 2005 at 19:34 UTC
    Attributes do allow to you build a better Exporter module. Damian has already done it (Perl6::Export::Attrs). I use it all the time.