From bb10db34d96aca27b3331cbb45510e9fa81e2c7c Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 20 Nov 2006 11:27:40 +0000 Subject: [PATCH] Extended build system to automatically add "use lib" where needed. --- lib/Simba/Build.pm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/Simba/Build.pm diff --git a/lib/Simba/Build.pm b/lib/Simba/Build.pm new file mode 100644 index 0000000..0e60734 --- /dev/null +++ b/lib/Simba/Build.pm @@ -0,0 +1,33 @@ +package Simba::Build; +use strict; +use warnings; + +use Module::Build; +use Data::Dumper; + +our @ISA = ('Module::Build'); + +sub ACTION_install { + my $self = shift; + # print STDERR Dumper($self), "\n"; + print STDERR $self->install_path->{lib}, "\n"; + print STDERR Dumper($self->install_map), "\n"; + my $lib = $self->install_map->{'blib/lib'}; + for my $script (glob('blib/script/*')) { + open (my $in, '<', $script) or die "cannot open $script: $!"; + open (my $out, '>', "$script.$$") or die "cannot open $script.$$: $!"; + while (<$in>) { + if (m{^use lib 'blib/lib'}) { + print $out "use lib '$lib';\n"; + } else { + print $out $_ or die "cannot write to $script.$$: $!"; + } + } + close $in or die "cannot close $script: $!"; + close $out or die "cannot close $script.$$: $!"; + rename "$script.$$", $script or die "cannot rename $script.$$ to $script: $!"; + } + $self->SUPER::ACTION_install; +} + +