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 ]

unimatrix (1124)

  (email not shown publicly)

Journal of unimatrix (1124)

Tuesday July 03, 2001
07:07 AM


[ #368 ]

Here is another module using attributes to simplify an API and hide implementation details. This time it's Exporter's API. Exporter::Simple, when used by a package, allows that package to define exports in a more concise way than using `Exporter'. Instead of having to worry what goes in `@EXPORT', `@EXPORT_OK' and `%EXPORT_TAGS', you can use two attributes to define exporter behavior:

    my @bar : Exportable(vars) = (2, 3, 5, 7);
    my $foo : Exported(vars) = 42;
    my %baz : Exported = (a => 65, b => 66);

    sub hello : Exported(greet,uk) { "hello there" }
    sub askme : Exportable { "what you will" }
    sub hi : Exportable(greet,us) { "hi there" }

You get the idea. I wasn't sure whether to emulate attributes for globals as well, but seeing that they're going to be in Perl 5.8.0, I'm going to wait until that's out before revising Exporter::Simple for a clean solution.

Enjoy. Feedback, as always, is welcome.