call.pl 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 $host = $ENV{DOMAIN} // 'localhost';
  12. my %env = (
  13. REQUEST_METHOD => $ARGV[0],
  14. PATH_INFO => $ARGV[1],
  15. QUERY_STRING => $ARGV[2],
  16. REQUEST_URI => "http://$host/".$ARGV[1],
  17. HTTP_HOST => $host
  18. );
  19. our $app = sub {
  20. my $self = TPSGI->new(TPSGI::get_config());
  21. return eval { $self->app(@_) } || do {
  22. my $env = shift;
  23. $env->{'psgi.errors'}->print($@);
  24. # Redact the stack trace past line 1, it usually has things which should not be shown
  25. $self->{cur_query}->{message} = $@;
  26. $self->{cur_query}->{message} =~ s/\n.*//g if $self->{cur_query}->{message};
  27. return $self->error($self->{cur_query});
  28. };
  29. };
  30. my $limit = $ARGV[3] || 1;
  31. for ( 0 .. $limit ) {
  32. my $out = $app->( \%env );
  33. print $out->[2][0];
  34. }