如何将程序包导入分组到单个自定义程序包中? [英] How do I group my package imports into a single custom package?

查看:70
本文介绍了如何将程序包导入分组到单个自定义程序包中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在编写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;

因此,如果我在perl程序中添加my_packages.pm,则需要所有上述包.

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

实际上我已经做了这个实验.但是我无法得到这个东西. 这意味着当我使用my_packages时.我无法获得使用严格,使用警告,使用Data :: Dumper"的功能.

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.....

推荐答案

看看 ,它将为您完成所有脏导入工作.

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

pod中的用法示例:

Usage example from pod:

创建工具集:

# 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

使用工具集:

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/

这篇关于如何将程序包导入分组到单个自定义程序包中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆