NAME Exporter::Declare - Declarative function exporting DESCRIPTION Declarative function exporting. You can export subs as usual with @EXPORT, or export anonymous subs under whatever name you want. You can also extend Exporter::Declare very easily. You can also add an export from outside the package using the export() class method on it. Exporter-Declare also provides a friendly interface to Devel::Declare magic. If you want to provide methods that work like MooseX::Declare or other Devel::Declare enhanced function, this is the module for you. There are a few common recipes available for formatting exports. EXPORTER SYNOPSIS Basic usage (No Devel-Declare) package MyPackage; use strict; use warnings; use Exporter::Declare; # works as expected our @EXPORT = qw/a/; # Declare an anonymous export export b => sub { 'b' }; export 'c'; sub c { 'c' } sub a { 'a' } 1; Enhanced Exporting Notice, no need for '=> sub', and trailing semicolon is optional. package MyPackage; use strict; use warnings; use Exporter::Declare; # Declare an anonymous export export b { 'b' } export c { 'c' } export d { 'd' } 1; Exporting Devel-Declare magic export sl sublike { ok( $name, "Got name" ); $code = pop(@_); } export cb codeblock { $code = pop(@_); } export mth method { $code = pop(@_); } export beg begin { my @args = @_; }; # Inject something into the start of the code block export injected method ( inject => 'my $arg2 = shift; ' ) { ... } # If you are brave and read up on Recipe's: export custom ( recipe => \%myrecipe ) { ... } Then to use those in the importing class: sl a { ... } cb { ... } mth { ok( $self, "got self" ); ... } # Same as BEGIN { beg(@args) }; beg( @args ); Extending (Writing your own Exporter-Declare) package MyExporterDeclare; use strict; use warnings; use Exporter::Declare ':extend'; export my_export => sub { my ( $name, $sub ) = @_; export( $name, $sub ); }; IMPORTER SYNOPSIS Normal package MyThing; use strict; use warnings; use MyThingThatExports; Import with a prefix package MyThing; use strict; use warnings; use MyThingThatExports ':prefix:myprefix'; Import only some subs package MyThing; use strict; use warnings; use MyThingThatExports qw/ sub_a sub_b /; RECIPES Writing custom recipes See Exporter::Declare::Recipe Provided Recipes Exporter::Declare::Recipe::Export Used for export() Exporter::Declare::Recipe::Sublike Things that act like sub name {} Exporter::Declare::Recipe::Codeblock Things that take a single codeblock as an arg. Like defining sub mysub(&) except that you do not need a semicolon at the end. Exporter::Declare::Recipe::Method Define codeblocks that have $self automatically shifted off. Exporter::Declare::Recipe::Begin Define a sub that works like 'use' in that it runs at compile time (like wrapping it in BEGIN{}) AUTHORS Chad Granum exodist7@gmail.com COPYRIGHT Copyright (C) 2010 Chad Granum Exporter-Declare is free software; Standard perl licence. Exporter-Declare is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.