Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I group my package imports into a single custom package?

Tags:

packages

perl

Normally when I am writing the perl program . I used to include following package .

use strict ; 
use warnings ; 
use Data::Dumper ;

Now , I want like this, I will not include all this package for every program . for that
I will have these all package in my own package. like following.

my_packages.pm

package my_packages  ; 
{
use strict ;
use warnings ;
use Data::Dumper;
}
1;

So, that if I add my_packages.pm in perl program , it needs have all above packages .

Actually I have done this experimentation . But I am not able get this things . which means when I am using my_packages . I am not able get the functionality of "use strict, use warnings , use Data::Dumper ".

Someone help me out of this problem.....

like image 654
Pavunkumar Avatar asked Mar 18 '10 06:03

Pavunkumar


1 Answers

Have a look at ToolSet, which does all the dirty import work for you.

Usage example from pod:

Creating a ToolSet:

# My/Tools.pm
package My::Tools;

use base 'ToolSet'; 

ToolSet->use_pragma( 'strict' );
ToolSet->use_pragma( 'warnings' );
ToolSet->use_pragma( qw/feature say switch/ ); # perl 5.10

# define exports from other modules
ToolSet->export(
 'Carp'          => undef,       # get the defaults
 'Scalar::Util'  => 'refaddr',   # or a specific list
);

# define exports from this module
our @EXPORT = qw( shout );
sub shout { print uc shift };

1; # modules must return true

Using a ToolSet:

use My::Tools;

# strict is on
# warnings are on
# Carp and refaddr are imported

carp "We can carp!";
print refaddr [];
shout "We can shout, too!";

/I3az/

like image 91
draegtun Avatar answered Sep 27 '22 22:09

draegtun