develooper Front page | perl.qa | Postings from March 2006

Re: Module::Build and installing in non-standard locations

Thread Previous | Thread Next
From:
Randy W. Sims
Date:
March 28, 2006 15:31
Subject:
Re: Module::Build and installing in non-standard locations
Message ID:
4429C730.2020506@thepierianspring.org
Matisse Enzer wrote:
> What's the standard (if any) for how to configure a build script to 
> install specific files (e.g. httpd.conf) in someplace other than the 
> standard Perl library/script/man locations?
> 
> For example, if my distro contains a bunch of .pm files and .pl files, 
> which go in the "normal" place, and my distro also contains:
> 
>    app_startup.pl
>    httpd.conf
> 
> and I want those installed as:
> 
>    app_startup.pl   => "$some_dir/app-startup.pl",  # mode 555
>    httpd.conf       => "$some_other_dir/conf",      # mode 444
> 
> is there a good standardized way to do this?

There are a number of ways to do this. The most simple is:

use strict;
use warnings;

use File::HomeDir;
my $conf_dir = File::Spec->catdir( File::HomeDir->my_home, '.Foo' );

use Module::Build;
my $builder = Module::Build->new(
     module_name  => 'Foo',
     license      => 'perl',

     conf_files => {
         'etc/httpd.conf' => 'conf/httpd.conf',
     },

     install_path => {
         'conf' => $conf_dir,
     },
);

$builder->add_build_element( 'conf' );

$builder->create_build_script();

__END__

The add_build_element() method is the key to the process. It lets M::B 
know it should look for a 'conf_files' property that describes files to 
be copied from somewhere in your distribution to a directory in 'blib'. 
In the above example, 'etc/httpd.conf' in your distribution root to 
'blib/conf/httpd.conf'.

Note that it's a current limitation that the first element of the 
directory name in blib must be the same as the name of the build 
element, in this case 'conf'.

Next the 'install_path' is looked at for a path to install build 
elements of that type. The build elements will be copied from the 
directory in 'blib' to the directory given. It is not necessary to 
specify the 'install_path' here; it can be specified on the command line 
by the user when invoking the install action:

   ./Build install --install-path conf=/etc/

If specified on the command line it will override the constructor arg. 
If it is not specified in either place, those files will not be 
installed, so it can be used as a flag.

Since we use ExtUtils::Install to install there is currently no way to 
specifiy the file mode.

This has turned out to be one of the most FAQ with Module::Build. There 
are plans to greatly simplify the process in the next version of M::B, 
including removing the above mentioned limitations.

There are also several other more advanced ways to accomplish the above 
by creating a subclass and providing methods to enumerate the files you 
want to install or to create the files to be installed. There are 
examples of these in Module::Build::Cookbook.

Also, there is a list dedicated to Module::Build which I've CC'd.

Regards,
Randy.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About