1 package Catalyst::ScriptRole;
5 use Catalyst::EngineLoader;
6 use Moose::Util::TypeConstraints;
7 use Catalyst::Utils qw/ ensure_class_loaded /;
8 use namespace::autoclean;
10 subtype 'Catalyst::ScriptRole::LoadableClass',
12 coerce 'Catalyst::ScriptRole::LoadableClass',
14 via { ensure_class_loaded($_); 1 };
16 with 'MooseX::Getopt' => {
20 _getopt_spec_exception
25 has application_name => (
26 traits => ['NoGetopt'],
33 isa => 'Catalyst::ScriptRole::LoadableClass',
36 default => 'Catalyst::EngineLoader',
37 documentation => 'The class to use to detect and load the PSGI engine',
41 isa => 'Plack::Loader',
44 $self->loader_class->new(application_name => $self->application_name);
47 load_engine => 'load',
48 autoload_engine => 'auto',
53 sub _getopt_spec_exception {}
55 sub _getopt_spec_warnings {
63 sub print_usage_text {
71 $self->_run_application;
74 sub _application_args {
78 extra_argv => $self->extra_argv,
82 sub _plack_loader_args {
84 my @app_args = $self->_application_args;
85 return (port => $app_args[0]);
88 sub _plack_engine_name {}
90 sub _run_application {
92 my $app = $self->application_name;
93 Class::MOP::load_class($app);
95 if (my $e = $self->_plack_engine_name ) {
96 $server = $self->load_engine($e, $self->_plack_loader_args);
99 $server = $self->autoload_engine($self->_plack_loader_args);
101 $app->run($self->_application_args, $server);
108 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
112 package MyApp::Script::Foo;
114 use namespace::autoclean;
116 with 'Catalyst::ScriptRole';
118 sub _application_args { ... }
122 Role with the common functionality of Catalyst scripts.
128 The method invoked to run the application.
132 =head2 application_name
134 The name of the application class, e.g. MyApp
144 Catalyst Contributors, see Catalyst.pm
148 This library is free software, you can redistribute it and/or modify
149 it under the same terms as Perl itself.