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 sub _plack_loader_args {
70 my @app_args = $self->_application_args;
71 return (port => $app_args[0]);
74 sub _run_application {
76 my $app = $self->application_name;
77 Class::MOP::load_class($app);
79 if (my $e = $self->can('_plack_engine_name') ) {
80 $server = $self->load_engine($self->$e, $self->_plack_loader_args);
83 $server = $self->autoload_engine($self->_plack_loader_args);
85 $app->run($self->_application_args, $server);
92 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
96 package MyApp::Script::Foo;
98 use namespace::autoclean;
100 with 'Catalyst::ScriptRole';
102 sub _application_args { ... }
106 Role with the common functionality of Catalyst scripts.
112 The method invoked to run the application.
116 =head2 application_name
118 The name of the application class, e.g. MyApp
128 Catalyst Contributors, see Catalyst.pm
132 This library is free software, you can redistribute it and/or modify
133 it under the same terms as Perl itself.