in reply to Re^4: Creating "parasitic" exports
in thread Creating "parasitic" exports
Given a::b.pm:
package a::b; require Exporter; our @ISA = qw[ Exporter ]; our @EXPORT = qw[ foo ]; our @EXPORT_OK = qw[ foo bar qux ]; our %EXPORT_TAGS = ( all => [ @EXPORT_OK ], ); sub foo{ print 'fooey|' } sub bar{ print 'Baaa!' } sub qux{ print 'Qux?!' } 1;
And a::b::c.pm:
package a::b::c; use a::b qw[ :all ]; require Exporter; our @ISA = qw[ Exporter ]; our @EXPORT = @a::b::EXPORT; our @EXPORT_OK = ( @a::b::EXPORT_OK, 'sensible' ); our %EXPORT_TAGS = %a::b::EXPORT_TAGS; push @{ $EXPORT_TAGS{ all } }, 'sensible'; sub sensible{ print 'sensible' } 1;
Then importer.pl:
#! perl -slw use a::b::c qw[ :all ]; foo(); bar(); qux(); sensible();
Produces this:
c:\test>importer fooey| Baaa! Qux?! sensible
Anything added to a::b.pm will automatically be available for import through a::b::c.pm without modifications.
|
|---|