call.pl 924 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env perl
  2. # Use to call specific routes
  3. use strict;
  4. use warnings;
  5. use FindBin::libs;
  6. use FindBin;
  7. chdir $FindBin::Bin;
  8. $ENV{HOME}=$FindBin::Bin;
  9. #Grab our custom routes
  10. use TPSGI;
  11. my %env = (
  12. REQUEST_METHOD => $ARGV[0],
  13. PATH_INFO => $ARGV[1],
  14. QUERY_STRING => $ARGV[2],
  15. REQUEST_URI => 'http://localhost/'.$ARGV[1],
  16. );
  17. our $app = sub {
  18. my $self = TPSGI->new(TPSGI::get_config());
  19. return eval { $self->app(@_) } || do {
  20. my $env = shift;
  21. $env->{'psgi.errors'}->print($@);
  22. # Redact the stack trace past line 1, it usually has things which should not be shown
  23. $self->{cur_query}->{message} = $@;
  24. $self->{cur_query}->{message} =~ s/\n.*//g if $self->{cur_query}->{message};
  25. return $self->error($self->{cur_query});
  26. };
  27. };
  28. my $limit = $ARGV[3] || 1;
  29. for ( 0 .. $limit ) {
  30. my $out = $app->( \%env );
  31. print $out->[2][0];
  32. }