Explorar o código

use libdir of included routers, don't have a fencepost error

George S. Baugh hai 8 meses
pai
achega
6d94c052e9
Modificáronse 2 ficheiros con 8 adicións e 3 borrados
  1. 5 1
      bin/tpsgi
  2. 3 2
      lib/TPSGI.pm

+ 5 - 1
bin/tpsgi

@@ -8,6 +8,7 @@ use strict;
 use warnings;
 
 use FindBin::libs;
+use File::Basename qw{dirname};
 
 use TPSGI;
 
@@ -37,7 +38,10 @@ sub main {
     my (@args) = @_;
 
     my %options = TPSGI::get_config();
-
+    foreach my $route (@{$options{routers}}) {
+        my $libdir = dirname($route);
+        push(@INC, $libdir);
+    }
     return %options;
 }
 

+ 3 - 2
lib/TPSGI.pm

@@ -203,7 +203,7 @@ sub new {
 
     # Refuse to run as wrong user, all config will be borked otherwise
     my $pname = getpwuid($>);
-    die "Must run as configured user!" unless $pname eq ($options{user} // '');
+    die "Must run as configured user (got: $pname, want: $options{user})!" unless $pname eq ($options{user} // '');
 
     my $self = bless(\%options, $class);
     $self->{ip} = '0.0.0.0';
@@ -562,8 +562,9 @@ sub _app {
 
             # Here's where you want to use Regexp::Debugger in the context of call.pl to debug routes... EX:
             # perl ./call.pl GET /path/to/route
+            print $r->[$_]."\n";
             $path =~ m/^$r->[$_]$/;
-        } 0..scalar(@$r);
+        } 0..scalar(@$r)-1;
         $route_actual = $r->[$matched+1] if defined($matched);
     }