Install custom files
Simon Ruderich <[email protected]> Fri, 1 Apr 2011 19:15:45 +0200
| Newsgroups | gmane.comp.lang.perl.modules.module-build |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I'm trying to install custom files to a specific location which
should be relative to the given prefix/install_base/.. In this
case into share/locale. So e.g. if --prefix=/usr/local then it
should install into /usr/local/share/locale/.
I'm using Module::Build 0.340201 on Debian Squeeze.
I tried the following ($class has a method process_locale_files()
which creates the files in blib/locale, that part works just
fine):
my $build = $class->new(
...
);
$build->add_build_element('locale');
$build->install_base_relpaths(locale => 'locale');
$build->create_build_script;
But no files get installed. After some testing it looks like
$build->install_base_relpaths() doesn't work at all -
$build->install_base_relpaths(lib => 'whatever') does nothing for
me, my .pm files are still installed in the same place.
I could use $build->install_path(locale => '...') but that
requires an absolute path. At the moment I'm using the following
hack to get the real installation path (I'm not sure if that's
even correct all the time):
sub install_base_path {
my $self = shift;
if (defined $self->install_base) {
return $self->install_base;
} elsif (defined $self->prefix) {
return $self->prefix;
} else {
return $self->original_prefix->{$self->installdirs};
}
}
It seems to work, but doesn't look like a good solution. Is there
a variable which returns the absolute installation prefix? I
couldn't find any in the documentation.
Btw. the real reason why I need this is to install .po/.mo files
in share/locale. Is there a simple way to do that? I attached my
current solution (including the hack above). If there's a better
way to handle that, please tell me.
Regards,
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
Build.PL
(text/x-perl, 1.2 KB)
#!/usr/bin/perl
use strict;
use warnings;
use Module::Build;
my $class = Module::Build->subclass(code => <<'EOF');
use File::Path ();
# Convert .po files to .mo and install them.
sub process_locale_files {
my $self = shift;
my $pos = $self->rscan_dir('po/', '.*\.po$');
foreach my $po (@$pos) {
$po =~ /^po\/(.+)\.po$/;
my $path = "blib/locale/$1/LC_MESSAGES";
my $mo = "$path/pabook.mo";
if (not $self->up_to_date($po, $mo)) {
File::Path::mkpath($path);
$self->do_system("msgfmt -o $mo $po");
}
}
}
# Get the prefix (or whatever Module::Build calls it) of the current
# installation.
sub install_base_path {
my $self = shift;
if (defined $self->install_base) {
return $self->install_base;
} elsif (defined $self->prefix) {
return $self->prefix;
} else {
return $self->original_prefix->{$self->installdirs};
}
}
EOF
my $build = $class->new(
...
);
# Install .mo files in share/locale.
$build->add_build_element('locale');
$build->install_path(locale => $build->install_base_path . "/share/locale");
$build->create_build_script;
signature.asc
(application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBCAAGBQJNlghBAAoJEJL+/bfkTDL5zNIP/3Irv0ZUdSg3xJ68NOsP1sj/ uFcgZnAY5GHzlAFFy43s8uDOZe+MDJSMBuUgGivGFzDWS01mFU9KnPoijuZ88LgG QmVbLCv94fy67CMMNxalxcg6GEtqQEzkJ+yyaBuR4dZ/AdNf8XUmSmE0upWxfDpD 1jseY4l8vvqc7ZXX58SJHC8FL4PidGezQxfeFtm1yOQ2ObfgvOOV4MKQHK90Lel+ sqC+pmp1yGQS7i0ZBkN8j9DcmrT4d8fKY/V89hwY+efJklzBl3ZCKOXB6FeYcrO3 xYg/NRijd5Cv+2f9KU4mz911DWrFTKV8qIJ2iASaWIrbLZYk6GwOh+yZCyVDILEB z+vqh6Qme+pbGdBKgWOLX2FOWXsfl0p70m7Zuh8XbLRzSVDQRZ/AezCrKPzgtbQl 9/VhdI/LQXEN99+LWO3z7Qwj+Q/C/O9+m91WO+Jety7ywdSGXvBkbrbDHNPy86I2 K1hw2C+Q9vA32rI+9eGQZq2co1rLxsy5sTSdNRbou1bdjZACvw2VOO/pKbSQ7yT7 Mogp6VQCJPypSJuvOq5w9NfWzuTK6VvRpGJ0UhZXDVZCE+zqFTu8SzdRrQltjoq8 BgDd2xrafBT8heQiI4rGFIFRoh8mttW4VR74IHb8rdie0B6qnxF8gShzt5BX88CX 3t2eR1t9meRRB3fmbW84 =1VV0 -----END PGP SIGNATURE-----