1 package Catalyst::ScriptRole;
3 use MooseX::Types::Moose qw/Str Bool/;
6 use Catalyst::EngineLoader;
7 use MooseX::Types::LoadableClass qw/LoadableClass/;
8 use namespace::autoclean;
10 with 'MooseX::Getopt' => {
13 _getopt_spec_exception
18 has application_name => (
19 traits => ['NoGetopt'],
29 default => 'Catalyst::EngineLoader',
30 documentation => 'The class to use to detect and load the PSGI engine',
34 isa => 'Plack::Loader',
37 $self->loader_class->new(application_name => $self->application_name);
40 load_engine => 'load',
41 autoload_engine => 'auto',
46 sub _getopt_spec_exception {}
48 sub _getopt_spec_warnings {
53 sub _getopt_full_usage {
61 $self->_run_application;
64 sub _application_args {
68 extra_argv => $self->extra_argv,
72 sub _plack_loader_args {
74 my @app_args = $self->_application_args;
75 return (port => $app_args[0]);
78 sub _plack_engine_name {}
80 sub _run_application {
82 my $app = $self->application_name;
83 Class::MOP::load_class($app);
85 if (my $e = $self->_plack_engine_name ) {
86 $server = $self->load_engine($e, $self->_plack_loader_args);
89 $server = $self->autoload_engine($self->_plack_loader_args);
91 $app->run($self->_application_args, $server);
98 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
102 package MyApp::Script::Foo;
104 use namespace::autoclean;
106 with 'Catalyst::ScriptRole';
108 sub _application_args { ... }
112 Role with the common functionality of Catalyst scripts.
118 The method invoked to run the application.
122 =head2 application_name
124 The name of the application class, e.g. MyApp
134 Catalyst Contributors, see Catalyst.pm
138 This library is free software, you can redistribute it and/or modify
139 it under the same terms as Perl itself.