Badger::Exporter

A symbol exporter.
Download

Badger::Exporter Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Andy Wardley
  • Publisher web site:
  • http://search.cpan.org/~abw/

Badger::Exporter Tags


Badger::Exporter Description

A symbol exporter. Badger::Exporter is a symbol exporter.SYNOPSISDefining a module subclassed from Badger::Exporter: package Badger::AnyModule; use base 'Badger::Exporter'; our ($WIZ, $BANG, @BING, %BONG);Specifying the exports using the all-in-one exports() method: __PACKAGE__->exports( all => '$WIZ $BANG', # like Exporter's @EXPORT any => '@BING %BONG', # like @EXPORT_OK tags => { # like %EXPORT_TAGS foobar => 'foo bar', }, hooks => { # custom hooks hello => sub { print "Hello World! " }, }, fail => sub { # handle unknown exports print "I'm sorry Dave, I can't do that. " }, );Or individual export_XXX() methods: # export all these symbols by default # methods can take either __PACKAGE__->export_all(qw( $WIZ $BANG )); # a list of symbols or a __PACKAGE__->export_all('$WIZ $BANG'); # space-delimited string # export these symbols if requested __PACKAGE__->export_any(qw( @BING %BONG )); # list __PACKAGE__->export_any('@BING %BONG'); # string # define sets of symbols for export __PACKAGE__->export_tags( set1 => , # list set2 => '@BING %BONG', # string set3 => 'foo bar', # string set4 => { # hash # use hash ref to define aliases for symbols foo => '&the_foo_sub', bar => '&the_bar_sub', }, ); # define hooks for import symbols __PACKAGE__->export_hooks( hello => sub { my ($class, $target, $symbol, $more_symbols) = @_; print $symbol, " ", shift(@$more_symbols), " "; } ); # define catch-all for any failed import symbols __PACKAGE__->export_fail( sub { my ($class, $target, $symbol, $more_symbols) = @_; warn "Cannot export $symbol from $class to $target "; } );Using the module: package main; # imports default items: $WIZ $BANG use Badger::AnyModule; # import specific items use Badger::AnyModule qw( $WIZ @BING ); # import user-defined sets use Badger::AnyModule qw( :set1 :set3 ); # specifying the :default set ($WIZ $BANG) and others use Badger::AnyModule qw( :default @BING ); # importing all symbols using the :all set use Badger::AnyModule ':all'; # specifying multiple symbols in a single string use Badger::AnyModule ':set1 $WIZ @BING'; # triggering import hooks: prints "hello world "; use Badger::AnyModule hello => 'world'; # import hooks and other items use Badger::AnyModule hello => 'world', qw( @BING %BONG ); # import fail hook gets called for any unknown symbols use Badger::AnyModule 'badger'; # warns: Cannot export badger from Badger::AnyModule to main # imports indicates that all remaining arguments are symbols to # import, bypassing any hooks use Badger::AnyModule hello => 'world' imports => qw( @BING %BONG ); # import (singular) option indicates that the next item is an # import symbols (or multiple symbols in a single string) and # disables hooks for that item only. use Badger::AnyModule import => '@BING %BONG'; This module performs the same basic function as the Exporter module in that it exports symbols from one package namespace to another.Howevever, unlike the Exporter module it also accounts for object inheritance. If your base class module defines a set of exportable symbols then any subclasses derived from it will also have that same set of symbols (and any others it adds) available for export.It implements a number of methods that simplify the process of defining what symbols can be exported, and provides a convenient mechanism for handling special import flags. Requirements: · Perl


Badger::Exporter Related Software