更改perl模块Module :: Build的默认源目录

时间:2013-08-29 09:21:10

标签: perl build module directory default

我正在研究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 /目录添加文件

1 个答案:

答案 0 :(得分: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