0

我正在研究 perl 模块 Module::Build 以创建模块。我需要知道是否有办法将所有 *.pm 文件的默认目录(lib/)更改为自定义目录。例如,*.pm 文件的源目录默认为“lib/directory”,我想将其更改为“home//pm/”并从中复制。

在daxim的评论后编辑:

我的目录结构如下:

home/user/workspace/try_ModuleBuild/LIBS/perl/Private/DB.pm
home/user/workspace/try_ModuleBuild/RELEASE/ModuleBuild/Build.PL
home/user/workspace/try_ModuleBuild/RELEASE/ModuleBuild/lib/API.pm
home/user/workspace/try_ModuleBuild/RELEASE/ModuleBuild/RESOURCES/prepare/form.html

所有文件都是空的。我的 Build.PL 包含:

my $self = Module::Build->new
    (
        module_name    =>   “Project”,
        dist_author    =>   [“My Name”],
        build_requires =>   {
                          'Test::More' => 0.98,
                                      'TAP::Harness' => 3.23
                    },
        dist_abstract       =>  “Example”,
        configure_requires  =>  { 'Module::Build' => 0.40 },
        requires        =>  {'perl' => '5.14.0'},
        add_to_cleanup          =>  [ 'Project::API-*' ],
        release_status      =>  'stable',
        use_tap_harness     =>  1,
        license         =>  'restrictive',
        RESOURCES_files => {'RESOURCES/prepare/form.html' =>'/RESOURCES/new/prepare/form.html'},

        lib_files=>{'/home/user/workspace/try_ModuleBuild/LIBS/perl/Private/DB.pm'=>'/lib/Private/DB.pm'},
        install_path           =>   {
                           'lib'=>'/home/user/MB/lib', 
                           'RESOURCES'=>"/home/user/MB/RESOURCES"
                                            },
);

    $self->add_build_element('RESOURCES');

    $self->add_build_element('lib');
    $self->create_build_script();

问题出在文件上:

home/user/workspace/try_ModuleBuild/LIBS/perl/Private/DB.pm'

因为它不在目录中:

home/user/workspace/try_ModuleBuild/RELEASE/ModuleBuild/LIBS

Build.PL 在哪里。

perl Build.PL
./Build manifest
./Build fakeinstall –install_base lib=/home/user/directory

fakeinstall 返回结果

“Installing /home/user/MB/lib/Private/DB.pm“

并且运行没有问题。

./Build dist

但是,创建的 .tar.gz 文件中缺少 DB.pm。

问题是我只能从 home/user/workspace/try_ModuleBuild/RELEASE/ModuleBuild/ 目录添加文件,而我想从 home/user/workspace/try_ModuleBuild/LIBS/perl/ 目录添加文件。

4

1 回答 1

0
use Module::Build;
use File::Copy 'cp';

my $class = Module::Build->subclass(code => <<'');
sub process_EXTRALIB_files {
    my ($self, $target) = @_;
    while (my ($from, $to) = each %{ $self->{properties}{"${target}_files"} }) {
        cp $from, $to;
        $self->_add_to_manifest('MANIFEST', $to);
    }
}

my $self = Module::Build->new(
    ⋮
    RESOURCES_files    => {'RESOURCES/prepare/form.html' => 'RESOURCES/new/prepare/form.html'},
    EXTRALIB_files     => {'../../LIBS/perl/Private/DB.pm' => '../lib/Private/DB.pm'},
);
$self->add_build_element('RESOURCES');
$self->add_build_element('EXTRALIB');
$self->create_build_script;

perl Build.PL
./Build
./Build manifest
./Build dist
于 2013-08-30T10:25:31.043 回答