Re: [Module::Build] add_property()
Status: Beta
Brought to you by:
kwilliams
|
From: Randy W. S. <ml...@th...> - 2006-03-09 11:40:31
|
Peter Scott wrote:
> My question about add_property was Warnocked; I'm going to give it one
> more go on the theory that folk may have been too busy with the P5P
> thread on M::B that started at the same time.
Sorry, not Warnocked. Just trying to sort through a backlog. I still
have your original message marked for follow-up...
As David said there will be better way to do this after 0.28. 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'},
);
$builder->add_build_element('yml');
$builder->create_build_script;
__END__
(tested on 0.2612 & 0.27x)
Your examples below don't do anything with the 'yml' files as shown;
they are not installed when './Build install' is run.
Before 0.28, I hope to write some accessors for install_path() and
friends to make things a bit cleaner. I really want to deprecate the
return of references to internal data, if possible.
Randy.
> I'm wondering why the add_property() method isn't exposed to the user?
> It seems that it would be handy for my case; I have a config.yml file
> that I want installed in the etc/ directory off my target, and I'm
> hardwiring the install_base here because this is something that gets
> used at a client site. I started with:
>
> my $builder = Module::Build->new
> (
> install_base => '/path/to/install',
> script_files => [ 'dummy' ],
> yml_files => { 'config.yml' =>
> '/path/to/install/etc/dummy.yml' },
> dist_name => 'dummy',
> dist_version_from => 'dummy',
> );
> $builder->add_build_element('yml');
> $builder->create_build_script;
>
> However, I don't like having to repeat /path/to/install in there. To
> remove the duplication I ended up doing:
>
> my $builder = Module::Build->new
> (
> install_base => '/path/to/install',
> script_files => [ 'dummy' ],
> dist_name => 'dummy',
> dist_version_from => 'dummy',
> );
> sub Module::Build::find_yml_files {
> my $self = shift;
> return { map $self->localize_file_path($_),
> 'config.yml' => $self->install_base . '/etc/dummy.yml'
> };
> }
> $builder->add_build_element('yml');
> $builder->create_build_script;
>
>
> But it seems that if I had been able to call add_property, it would have
> been simpler:
>
> my $builder = Module::Build->new
> (
> install_base => '/path/to/install',
> script_files => [ 'dummy' ],
> dist_name => 'dummy',
> dist_version_from => 'dummy',
> );
> $builder->add_property('yml_files'); # Method not found
> $builder->yml_files({ 'config.yml' => $self->install_base .
> '/etc/dummy.yml' });
> $builder->add_build_element('yml');
> $builder->create_build_script;
|