[Module::Build] dynamic creation?
Status: Beta
Brought to you by:
kwilliams
From: Gene B. <gb...@si...> - 2006-05-21 19:11:51
|
How do I generate the main, module_name package via the PL_files? I have Module::Build 0.2801 and (as with previous versions) get this instead of a Build file: ~/bin/Foo-Bar> perl Build.PL --foo=wtf Can't find file lib/Foo/Bar.pm to determine version at /usr/lib/perl5/site_perl/5.8.8/Module/Build/Base.pm line 934. Here are the relevant, plain-Jane files I'm using: ### Build.PL file: #!/usr/bin/perl use strict; use warnings; use Module::Build; my $build = Module::Build->new( module_name => 'Foo::Bar', license => 'perl', PL_files => { 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm', }, ); $build->create_build_script(); ### Bar.pm.PL file: #!/usr/bin/perl use strict; use warnings; use My::Module::Build; my $build = My::Module::Build->current(); my $foo = $build->args( 'foo' ); use IO::File; my $fh = IO::File->new( '> '. shift ); print $fh <<PACKAGE; package Foo::Bar; our \$VERSION = '0.00_1'; use strict; use warnings; sub foo { return $foo } 1; PACKAGE close $fh; I have tried subclassing, in order to create the main module before its version is checked, by adding ACTION_code() to a copy of Module::Build::Base->new() like so: package My::Module::Build; use base qw( Module::Build ); use strict; use warnings; sub new { my $self = shift()->_construct(@_); $self->{invoked_action} = $self->{action} ||= 'Build_PL'; $self->cull_args(@ARGV); die "Too early to specify a build action '$self->{action}'. Do 'Build $self->{action}' instead.\n" if $self->{action} && $self->{action} ne 'Build_PL'; $self->dist_name; $self->ACTION_code; # XXX Added to pre-create the main module. $self->dist_version; $self->check_manifest; $self->check_prereq; $self->check_autofeatures; $self->_set_install_paths; $self->_find_nested_builds; return $self; } This works just fine (although you get "No build_params? at /usr/lib/perl5/site_perl/5.8.8/Module/Build/Base.pm line 995." warnings) -unless- you try to use My::Module::Build->current() and get at the $build object in the generating Bar.pm.PL file. If so, you get the familiar, "Can't find file lib/Foo/Bar.pm to determine version" fatal error. Hints? Help? Thank you, Gene Boggs |