Thread: [Module::Build] add_property()
Status: Beta
Brought to you by:
kwilliams
|
From: Peter S. <Pe...@PS...> - 2006-03-08 16:26:16
|
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.
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;
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
http://www.perlmedic.com/
|
|
From: David W. <da...@ki...> - 2006-03-08 16:52:34
|
On Mar 4, 2006, at 11:22, Peter Scott wrote:
> 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;
With Randy's proposal from a few days ago, once he gets 'round to
implementing it (or I do if I have the tuits) after 0.28, you'll be
able to do this:
my $builder = Module::Build->new(
install_base => '/path/to/install',
script_files => [ 'dummy' ],
dist_name => 'dummy',
dist_version_from => 'dummy',
);
$builder->auto_build_elements(
element => 'yml',
filter => 'yml/*.yml',
install_relpath => 'etc',
);
$builder->create_build_script;
Cool, eh?
Best,
David
|
|
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;
|
|
From: Peter S. <Pe...@PS...> - 2006-03-11 02:12:29
|
At 03:40 AM 3/9/2006, Randy W. Sims wrote:
>As David said there will be better way to do this after 0.28.
Joy :-)
>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'},
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.
>);
>
>$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.
You're right. I was following the wrong path in the code and looking
at stuff that happens at build time.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
http://www.perlmedic.com/
|
|
From: Ken W. <ke...@ma...> - 2006-03-12 03:31:32
|
On Mar 10, 2006, at 9:13 PM, Peter Scott wrote: > 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 ); Yeah, that's kind of a David-specific thing. =) He was working on getting the whole contents of a directory $foo/ installed into $install_base/$foo/ . -Ken |
|
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.
|
|
From: David W. <da...@ki...> - 2006-03-16 02:51:57
|
On Mar 15, 2006, at 17:57, Randy W. Sims wrote:
> $builder->add_build_element('yml');
> $builder->install_path(
> 'yml' => File::Spec->catdir($builder->install_base, 'etc'),
> );
>
> $builder->create_build_script;
Nice.
> 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
Cool, as long as install_base doesn't change after the call to
install_path(). :-) Since that's a problem that I have, I eagerly
await your auto_build_elements() method.
Best,
David
|