tarbaby 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env perl
  2. # PODNAME: tarbaby
  3. # ABSTRACT: starman, with the autoreload that tPSGI does without Plack::Loader::Restarter
  4. use 5.040;
  5. use warnings FATAL => 'all';
  6. use re '/aa';
  7. use FindBin::libs;
  8. use Plack::Runner;
  9. use File::Basename qw{dirname};
  10. use TPSGI::Startup;
  11. =head1 USAGE
  12. tarbaby [--preload-app] [starman options] bin/tpsgi
  13. Starman, run as plackup would run it, with the server that
  14. L<Plack::Handler::TPSGI> provides. Before it forks, it sets up inotify watches
  15. on F<lib/> and on the directory of each router, so that a worker notices a
  16. changed module and restarts the server, when C<autoreload> is on. The workers
  17. load the application when they start, unless C<--preload-app> is passed.
  18. =cut
  19. sub version {
  20. require Starman;
  21. print "Starman $Starman::VERSION\n";
  22. return;
  23. }
  24. # Setup the watcher for changes
  25. # This has to be setup at global server start rather than app start per worker.
  26. # This is preferable to using -R (Plack::Loader::Restarter, see notes in orig starman)
  27. my %options = TPSGI::Startup::get_config();
  28. my @dirs = ("$options{tpsgi_dir}/lib");
  29. foreach my $route ( @{ $options{routers} } ) {
  30. push( @dirs, dirname("$options{tpsgi_dir}/$route") );
  31. }
  32. TPSGI::Startup::watch_for_changes(@dirs);
  33. my $preload_app;
  34. require Getopt::Long;
  35. Getopt::Long::Configure(qw{no_ignore_case no_auto_abbrev pass_through});
  36. Getopt::Long::GetOptions(
  37. "preload-app" => \$preload_app,
  38. );
  39. my @args = ( server => 'TPSGI', env => 'deployment', version_cb => \&version );
  40. if ( !$preload_app ) {
  41. push @args, 'loader' => 'Delayed';
  42. }
  43. my @argv = @ARGV;
  44. my $runner = Plack::Runner->new(@args);
  45. $runner->parse_options(@argv);
  46. $runner->set_options( argv => \@argv );
  47. $runner->run;