1 package Catalyst::ScriptRole;
5 use Catalyst::EngineLoader;
6 use Moose::Util::TypeConstraints;
7 use Catalyst::Utils qw/ ensure_class_loaded /;
8 use Class::Load 'load_class';
9 use namespace::autoclean;
11 subtype 'Catalyst::ScriptRole::LoadableClass',
13 coerce 'Catalyst::ScriptRole::LoadableClass',
15 via { ensure_class_loaded($_); 1 };
17 with 'MooseX::Getopt' => {
21 _getopt_spec_exception
26 has application_name => (
27 traits => ['NoGetopt'],
34 isa => 'Catalyst::ScriptRole::LoadableClass',
37 default => 'Catalyst::EngineLoader',
38 documentation => 'The class to use to detect and load the PSGI engine',
42 isa => 'Plack::Loader',
45 $self->loader_class->new(application_name => $self->application_name);
48 load_engine => 'load',
49 autoload_engine => 'auto',
54 sub _getopt_spec_exception {}
56 sub _getopt_spec_warnings {
61 sub print_usage_text {
69 $self->_run_application;
72 sub _application_args {
76 extra_argv => $self->extra_argv,
80 sub _plack_loader_args {
82 my @app_args = $self->_application_args;
83 return (port => $app_args[0]);
86 sub _plack_engine_name {}
88 sub _run_application {
90 my $app = $self->application_name;
93 if (my $e = $self->_plack_engine_name ) {
94 $server = $self->load_engine($e, $self->_plack_loader_args);
97 $server = $self->autoload_engine($self->_plack_loader_args);
99 $app->run($self->_application_args, $server);
106 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
110 package MyApp::Script::Foo;
112 use namespace::autoclean;
114 with 'Catalyst::ScriptRole';
116 sub _application_args { ... }
120 Role with the common functionality of Catalyst scripts.
126 The method invoked to run the application.
128 =head2 print_usage_text
130 Prints out the usage text for the script you tried to invoke.
134 =head2 application_name
136 The name of the application class, e.g. MyApp
146 Catalyst Contributors, see Catalyst.pm
150 This library is free software, you can redistribute it and/or modify
151 it under the same terms as Perl itself.