]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1272673 - make app.psgi runnable
authorDylan William Hardison <dylan@hardison.net>
Sat, 25 Feb 2017 18:29:44 +0000 (18:29 +0000)
committerDylan William Hardison <dylan@hardison.net>
Sun, 26 Mar 2017 02:03:57 +0000 (19:03 -0700)
README.rst
app.psgi

index a1dc598a7b97de9833b1a0003dcac6615d97070a..53fc3b3ae808f055f0406018e34c2a2917dc5214 100644 (file)
@@ -53,7 +53,7 @@ Finally, a webserver can be started by the following:
 
 .. code-block:: bash
 
-    perl -Ilocal/lib/perl5 local/bin/plackup
+    perl app.psgi
 
 Navigate to http://localhost:5000/ and login with the username and password provided earlier to checksetup.
 Remember to set the urlbase on http://localhost:5000/editparams.cgi. "http://localhost:5000" will probably suffice.
index 9f8957e99770a7e3658f43e4dc0c37d7cd9d3b85..5ac3cf14f7c3c790415d15af4de4ee423253a498 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -12,10 +12,19 @@ use warnings;
 
 use File::Basename;
 use File::Spec;
+
 BEGIN {
     require lib;
-    my $dir = dirname(__FILE__);
-    lib->import($dir, File::Spec->catdir($dir, "lib"), File::Spec->catdir($dir, qw(local lib perl5)));
+    my $dir = File::Spec->rel2abs( dirname(__FILE__) );
+    lib->import(
+        $dir,
+        File::Spec->catdir( $dir, "lib" ),
+        File::Spec->catdir( $dir, qw(local lib perl5) )
+    );
+
+    # disable "use lib" from now on
+    no warnings qw(redefine);
+    *lib::import = sub { };
 }
 
 use Bugzilla::Constants ();
@@ -37,8 +46,9 @@ use constant STATIC => qw(
     skins
 );
 
-builder {
-    my $static_paths = join('|', STATIC);
+my $app = builder {
+    my $static_paths
+        = join( '|', sort { length $b <=> length $a || $a cmp $b } STATIC );
     enable 'Static',
         path => qr{^/($static_paths)/},
         root => Bugzilla::Constants::bz_locations->{cgi_path};
@@ -48,10 +58,13 @@ builder {
     my $map = Plack::App::URLMap->new;
 
     my @cgis = glob('*.cgi');
-    my $shutdown_app = Plack::App::WrapCGI->new(script => 'shutdown.cgi')->to_app;
+    my $shutdown_app
+        = Plack::App::WrapCGI->new( script => 'shutdown.cgi' )->to_app;
 
     foreach my $cgi_script (@cgis) {
-        my $app = eval { Plack::App::WrapCGI->new(script => $cgi_script)->to_app };
+        my $app
+            = eval { Plack::App::WrapCGI->new( script => $cgi_script )->to_app };
+
         # Some CGI scripts won't compile if not all optional Perl modules are
         # installed. That's expected.
         if ($@) {
@@ -61,15 +74,28 @@ builder {
 
         my $wrapper = sub {
             my $ret = Bugzilla::init_page();
-            my $res = ($ret eq '-1' && $cgi_script ne 'editparams.cgi') ? $shutdown_app->(@_) : $app->(@_);
+            my $res
+                = ( $ret eq '-1' && $cgi_script ne 'editparams.cgi' )
+                ? $shutdown_app->(@_)
+                : $app->(@_);
             Bugzilla::_cleanup();
             return $res;
         };
 
         my $base_name = basename($cgi_script);
-        $map->map('/' => $wrapper) if $cgi_script eq 'index.cgi';
-        $map->map('/rest' => $wrapper) if $cgi_script eq 'rest.cgi';
-        $map->map("/$base_name" => $wrapper);
+        $map->map( '/'     => $wrapper ) if $cgi_script eq 'index.cgi';
+        $map->map( '/rest' => $wrapper ) if $cgi_script eq 'rest.cgi';
+        $map->map( "/$base_name" => $wrapper );
     }
-    my $app = $map->to_app;
+    $map->to_app;
 };
+
+unless (caller) {
+    require Plack::Runner;
+    my $runner = Plack::Runner->new;
+    $runner->parse_options(@ARGV);
+    $runner->run($app);
+    exit 0;
+}
+
+return $app;