diff options
-rwxr-xr-x | setenv.pl | 59 | ||||
-rwxr-xr-x | web/fixmystreet_app_cgi.cgi | 11 | ||||
-rwxr-xr-x | web/fixmystreet_app_fastcgi.cgi | 11 |
3 files changed, 60 insertions, 21 deletions
@@ -3,32 +3,53 @@ use strict; use warnings; -use FindBin; use List::MoreUtils 'uniq'; +my $root; + +BEGIN { # add the local perllibs too + + # Can't use Path::Class here as we'd load the old debian one. + $root = + __FILE__ =~ m{^(.*)/web/\.\..*$} + ? $1 + : `pwd`; + chomp($root); + + # warn "-----------------------\n"; + # warn "__FILE__: " . __FILE__ . "\n"; + warn '$root: ' . $root . "\n"; + + # warn '$0: ' . $0 . "\n"; + # warn "-----------------------"; +} + # Set the environment for the FixMyStreet project -# Add the lii/perl5 in perl-external so that we can load local::lib from there -use lib "$FindBin::Bin/perl-external/lib/perl5"; +# Add the lib/perl5 in perl-external so that we can load local::lib from there +use lib "$root/perl-external/lib/perl5"; # Add the perl-external dirs properly using local::lib -use local::lib "$FindBin::Bin/perl-external"; -use local::lib "$FindBin::Bin/perl-external/local-lib"; +use local::lib "$root/perl-external"; +use local::lib "$root/perl-external/local-lib"; -# add the local perllibs too -for ( "$FindBin::Bin/commonlib/perllib", "$FindBin::Bin/perllib" ) { +use lib "$root/commonlib/perllib"; +use lib "$root/perllib"; +for ( "$root/commonlib/perllib", "$root/perllib" ) { $ENV{PERL5LIB} = "$_:$ENV{PERL5LIB}"; } # also set the path to our scripts etc -$ENV{PATH} = join ':', uniq "$FindBin::Bin/bin", split( m/:/, $ENV{PATH} ); +$ENV{PATH} = join ':', uniq "$root/bin", split( m/:/, $ENV{PATH} ); # now decide what to do - if no arguments print out shell arguments to set the # environment. If there are arguments then run those so that they run correctly if (@ARGV) { system @ARGV; } -else { + +# we might want to require this file to configure something like a CGI script +elsif ( $0 eq __FILE__ ) { my @keys = sort 'PATH', grep { m{^PERL} } keys %ENV; @@ -54,3 +75,23 @@ else { STOP } +else { + + # we were just required - unload some modules to prevent old code + # getting in the way of loading newer code from the newly set directories. + use Class::Unload; + + my @modules = + sort + grep { m/File::/ } + map { s{\.pm$}{}; s{/}{::}g; $_ } + grep { m{\.pm$} } + keys %INC; + + for (@modules) { + Class::Unload->unload($_); + } +} + +1; + diff --git a/web/fixmystreet_app_cgi.cgi b/web/fixmystreet_app_cgi.cgi index c656cab5b..7d60ce673 100755 --- a/web/fixmystreet_app_cgi.cgi +++ b/web/fixmystreet_app_cgi.cgi @@ -1,13 +1,12 @@ #!/usr/bin/env perl -# set all the paths to the perl code -use FindBin; -use lib "$FindBin::Bin/../commonlib/perllib"; -use lib "$FindBin::Bin/../perllib"; -use local::lib "$FindBin::Bin/../local-lib5"; +BEGIN { # set all the paths to the perl code + use FindBin; + require "$FindBin::Bin/../setenv.pl"; +} use Catalyst::ScriptRunner; -Catalyst::ScriptRunner->run('FixMyStreet::App', 'CGI'); +Catalyst::ScriptRunner->run( 'FixMyStreet::App', 'CGI' ); 1; diff --git a/web/fixmystreet_app_fastcgi.cgi b/web/fixmystreet_app_fastcgi.cgi index 03566029b..1059cbd34 100755 --- a/web/fixmystreet_app_fastcgi.cgi +++ b/web/fixmystreet_app_fastcgi.cgi @@ -1,13 +1,12 @@ #!/usr/bin/env perl -# set all the paths to the perl code -use FindBin; -use lib "$FindBin::Bin/../commonlib/perllib"; -use lib "$FindBin::Bin/../perllib"; -use local::lib "$FindBin::Bin/../local-lib5"; +BEGIN { # set all the paths to the perl code + use FindBin; + require "$FindBin::Bin/../setenv.pl"; +} use Catalyst::ScriptRunner; -Catalyst::ScriptRunner->run('FixMyStreet::App', 'FastCGI'); +Catalyst::ScriptRunner->run( 'FixMyStreet::App', 'FastCGI' ); 1; |