Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Create a package that exports other packages

by exilepanda (Friar)
on Aug 06, 2014 at 06:27 UTC ( [id://1096392]=perlquestion: print w/replies, xml ) Need Help??

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

Sorry if I give inappropriate title, I don't know what is it call. Say that I have X, Y ( and a lot more) packages, and now I want to create a package MyStandardStuffs, when I use this package, I can access to all X, Y provided methods or functions like this:
use MyStandardStuffs; my $x = new X; my $y1 = new Y; my $y2 = someExportedFunction('foo bar'); # from package Y
Any clues for me to study ? Thanks in advance

Replies are listed 'Best First'.
Re: Create a package that exports other packages
by Anonymous Monk on Aug 06, 2014 at 06:46 UTC
      BIG THANKS!! Import::Into works like a charm!!! It goes exactly I would expect and feel really transparent!
      # X.pm package X; sub new { bless{ Name=> "I am X"}, shift} 1; #Y.pm package Y; require Exporter; our @ISA =qw/Exporter/; our @EXPORT_OK = qw/TestY/; sub new {bless{ Name=> "I am Y"}, shift;} sub TestY {print "@_ EXPORT_OK"} 1; #MyStuffs.pm package MyStuffs; use Import::Into; sub import { my $target = caller; X->import::into($target); Y->import::into($target, qw/TestY/); } 1; #main.pl use MyStuffs; use Data::Dumper; my $x = new X; my $y = new Y; print "X dumps: "; print Dumper $x; print "$/$/Y dumps: "; print Dumper $y; print "$/$/"; TestY("I am"); print "$/"; Y::TestY ( "Still" ) ; __END__ X dumps: $VAR1 = bless( { 'Name' => 'I am X' }, 'X' ); Y dumps: $VAR1 = bless( { 'Name' => 'I am Y' }, 'Y' ); I am EXPORT_OK Still EXPORT_OK
Re: Create a package that exports other packages
by Bloodnok (Vicar) on Aug 06, 2014 at 10:15 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1096392]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found