Re: [Module::Build] add_property()
Status: Beta
Brought to you by:
kwilliams
|
From: Randy W. S. <ml...@th...> - 2006-03-16 01:57:59
|
Peter Scott wrote:
> At 03:40 AM 3/9/2006, Randy W. Sims wrote:
>> As of current cvs the way I would probably write this is:
>>
>> use strict;
>> use warnings;
>>
>> use Module::Build;
>>
>> my $build_class = Module::Build->subclass(code => <<'EOC');
>>
>> sub new {
>> my $class = shift;
>> my $self = $class->SUPER::new(@_);
>>
>> $self->install_path->{'yml'} =
>> $self->localize_file_path($self->install_base . '/etc');
>>
>> return $self;
>> }
>>
>> EOC
>>
>> my $builder = $build_class->new(
>> dist_name => 'Foo',
>> dist_version_from => 'lib/Foo.pm',
>>
>> install_base => '/home/randys/tmp/Foo',
>>
>> yml_files => {'config.yml' => 'yml/config.yml'},
I've documented the install_path() accessor now, so the above becomes:
use strict;
use warnings;
use File::Spec;
use Module::Build;
my $builder = Module::Build->new(
dist_name => 'Foo',
dist_version_from => 'lib/Foo.pm',
install_base => '/home/randys/tmp/Foo',
yml_files => {'config.yml' => 'yml/config.yml'},
);
$builder->add_build_element('yml');
$builder->install_path(
'yml' => File::Spec->catdir($builder->install_base, 'etc'),
);
$builder->create_build_script;
__END__
The constructor tells it to copy the 'config.yml' in the root directory
of your distribution (the directory containing 'Build.PL') and copy it
to 'blib/yml/config.yml'.
The call to install_path tells it where to install the yml files
relative to install_base. In the above example it would install into
/home/randys/tmp/Foo/etc/config.yml
> What wasn't obvious until I spent some time doing it wrong was that the
> config.yml above *must* be in a subdirectory called 'yml'. I had
> initially called it 'etc' and finally hauled out the debugger which led
> me to where the code does
>
> my $localdir = File::Spec->catdir( $blib, $type );
>
> That was something I did not glean at all from reading the "Adding new
> file types to the install process" section of the cookbook, which
> somehow avoids having to put .dat files into a /dat directory.
I'll see if that can be cleared up some; maybe another recipe in the
Cookbook.
Also, I'm off to backpan to retrieve every release version of
Module::Build. I'm going to scan the docs and make a compatibility
matrix to document when each method/accessor was added. I'll add it to
the docs as a note under each heading like:
=install_path()
[version 0.28]
blah blah...
=cut
If I can figure a way to draw out the matrix itself, I'll find a place
to put it.
Randy.
|