Thread: [Module::Build] How do I make a Build.PL to install a web app?
Status: Beta
Brought to you by:
kwilliams
From: Stephen A. <spa...@gm...> - 2006-04-14 01:29:24
|
Hi, 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 "sha= re". How can I do this? (See examples below.) Is the "install_extra_dirs" option a good enhancement? (see below) I have a way to do this (barely) with MakeMaker, and if I can't figure out = how to do this with Module::Build, I will have to go back to Makefile.PL in som= e of my distributions. Stephen ######################################################### # Build.PL (with desired features) ######################################################### use Module::Build; my $build =3D Module::Build->new ( dist_name =3D> "Foo-WebApp", dist_version_from =3D> "lib/Foo/WebApp.pm", dist_author =3D> "sadkins\@therubicongroup.com", dist_abstract =3D> "A hot Web App", license =3D> "perl", # this is the desired new option. # it would install the directories and all files from the distribution # directory to the "install_base" directory. # i.e. "./htdocs" gets copied to "/usr/local/htdocs". # meanwhile, shebang substitution also takes place. install_extra_dirs =3D> [ "bin", "cgi-bin", "htdocs", "share" ], ); $build->create_build_script; ######################################################### # Makefile.PL (which basically does the job) ######################################################### ###################################################################### ## File: $Id: Makefile.PL,v 1.2 2005/04/13 17:53:58 spadkins Exp $ ###################################################################### use ExtUtils::MakeMaker; my @programs =3D <bin/[a-z]*>; WriteMakefile( 'NAME' =3D> 'Foo-WebApp', 'DISTNAME' =3D> 'Foo-WebApp', 'VERSION_FROM' =3D> 'lib/Foo/WebApp.pm', 'EXE_FILES' =3D> [ @programs ], ); # Note: The PREFIX variable must be set at "make" time. sub MY::postamble { return <<EOF; install :: @\$(MOD_INSTALL) htdocs \$(PREFIX)/htdocs @\$(MOD_INSTALL) cgi-bin \$(PREFIX)/cgi-bin @\$(MOD_INSTALL) share \$(PREFIX)/share \$(PERL) -e "mkdir('\$(PREFIX)/log') if (! -d '\$(PREFIX)/log');" EOF } |
From: Randy W. S. <ml...@th...> - 2006-04-14 10:12:10
|
Stephen Adkins wrote: > Hi, > > 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". > > How can I do this? (See examples below.) > Is the "install_extra_dirs" option a good enhancement? (see below) > > I have a way to do this (barely) with MakeMaker, and if I can't figure out how > to do this with Module::Build, I will have to go back to Makefile.PL in some > of my distributions. 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). If we're going to extend/enhance this functionality, I think we need to take a different approach than feeding yet more arguments to the constructor since it doesn't really accomplish any more than we can do now. In particular it's not flexible enough to specify file to file and directory to directory copies, nor does it allow custom attributes/file modes to be assigned. As we've talked about before, I'd like to add a method to allow easy, one call, way to set up custom install elements. But I'm holding off in the interest of getting 0.28 out. This is a very high priority item with all of the questions we get about it, but we really need to get 0.28 out. I'll try to get the docs updated a bit to help authors understand the current methods better for the 0.28 release. Regards, Randy. |
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. |