[Module::Build] Re: How do I make a Build.PL to install a web app?
Status: Beta
Brought to you by:
kwilliams
|
From: Julian M. <ju...@me...> - 2006-04-14 10:38:02
|
Randy W. Sims wrote:
> Stephen Adkins wrote:
> > I want to have a Build.PL which installs more than just scripts and
> > modules. I have a web application, and I want to install "cgi-bin"
> > programs, lots of files under "htdocs" (html, css, js, jpg, png, gif),
> > and various files under "share".
> > [...]
>
> I understand and agree with the need, but I'm not sure this is the best
> approach.
>
> We have one approach already that consists of feeding arguments to the
> constructor to indicate extra files to copy. This can be extended by
> subclassing and adding appropriate methods (eg find_${type}_files and
> process_${type}_files).
For the record, I was one of those who have asked this question here
before. This is what I have come up with and been using so far (abridged
example taken from a CGI app of mine):
use Module::Build 0.26;
my $class = Module::Build->subclass( code => <<'EOF' );
sub process_extra_files {
my ($self, $dir) = @_;
$dir ||= $element;
File::Find::find(
{
wanted => sub {
$File::Find::prune = 1 if -d and /\.svn$/;
# Exclude .svn dirs.
return if not -f;
# Handle files only.
my $destination = $self->copy_if_modified(
from => $File::Find::name,
to => File::Spec->catfile(
$self->blib, $File::Find::name)
);
return if not defined($destination);
# Already up to date?
chmod((stat($File::Find::name))[2], $destination)
or warn("Couldn't set permissions on $destination: $!");
},
no_chdir => 1
},
$dir
);
}
sub process_etc_files { shift->process_extra_files('etc') }
sub process_cgi_bin_files { shift->process_extra_files('cgi-bin') }
sub process_sbin_files { shift->process_extra_files('sbin') }
sub process_www_files { shift->process_extra_files('www') }
EOF
my $build = $class->new(
module_name => 'Thingy',
# ...
dist_version_from
=> 'cgi-bin/thingy',
# ...
install_path => {
'etc' => '/etc/thingy',
'cgi-bin' => '/usr/lib/cgi-bin',
'sbin' => '/usr/sbin',
'lib' => '/usr/share/thingy/lib',
'www' => '/usr/share/thingy/www',
},
# ...
create_makefile_pl
=> 'passthrough',
);
$build->add_build_element($_)
foreach qw(etc cgi_bin sbin www);
$build->create_build_script();
__END__
I would like to see a more elegant solution to the custom-installation-
dirs problem in 0.28, too.
|