tarbaby 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env perl
  2. # Minor modifications to starman to support autoreload of code without Plack::Loader::Restarter.
  3. use strict;
  4. use FindBin::libs;
  5. use Plack::Runner;
  6. use File::Basename qw{dirname};
  7. use TPSGI::Startup;
  8. sub version {
  9. require Starman;
  10. print "Starman $Starman::VERSION\n";
  11. }
  12. # Setup the watcher for changes
  13. # This has to be setup at global server start rather than app start per worker.
  14. # This is preferable to using -R (Plack::Loader::Restarter, see notes in orig starman)
  15. my %options = TPSGI::Startup::get_config();
  16. my @dirs = ("$options{tpsgi_dir}/lib");
  17. foreach my $route (@{$options{routers}}) {
  18. push(@dirs, dirname("$options{tpsgi_dir}/$route"));
  19. }
  20. TPSGI::Startup::watch_for_changes(@dirs);
  21. my $preload_app;
  22. require Getopt::Long;
  23. Getopt::Long::Configure("no_ignore_case", "no_auto_abbrev", "pass_through");
  24. Getopt::Long::GetOptions(
  25. "preload-app" => \$preload_app,
  26. );
  27. my @args = (server => 'TPSGI', env => 'deployment', version_cb => \&version);
  28. if (!$preload_app) {
  29. push @args, 'loader' => 'Delayed';
  30. }
  31. my @argv = @ARGV;
  32. my $runner = Plack::Runner->new(@args);
  33. $runner->parse_options(@argv);
  34. $runner->set_options(argv => \@argv);
  35. $runner->run;