1 package Catalyst::ScriptRole;
3 use MooseX::Types::Moose qw/Str Bool/;
6 use Catalyst::Engine::Loader;
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 documentation => 'Display this help and exit',
30 cmd_aliases => ['?', 'h'],
37 default => 'Catalyst::Engine::Loader',
38 documentation => 'The class to use to detect and load the PSGI engine',
42 isa => 'Plack::Loader',
44 shift->loader_class->new
47 load_engine => 'load',
48 autoload_engine => 'auto',
53 sub _getopt_spec_exception {}
55 sub _getopt_spec_warnings {
60 sub _getopt_full_usage {
68 $self->_getopt_full_usage if $self->help;
73 $self->_run_application;
76 sub _application_args {
80 sub _plack_loader_args {
81 my @app_args = shift->_application_args;
82 return (port => $app_args[0]);
85 sub _run_application {
87 my $app = $self->application_name;
88 Class::MOP::load_class($app);
90 if (my $e = $self->can('_plack_engine_name') ) {
91 $server = $self->load_engine($self->$e, $self->_plack_loader_args);
94 $server = $self->autoload_engine($self->_plack_loader_args);
96 $app->run($self->_application_args, $server);
103 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
107 package MyApp::Script::Foo;
109 use namespace::autoclean;
111 with 'Catalyst::ScriptRole';
113 sub _application_args { ... }
117 Role with the common functionality of Catalyst scripts.
123 The method invoked to run the application.
127 =head2 application_name
129 The name of the application class, e.g. MyApp
139 Catalyst Contributors, see Catalyst.pm
143 This library is free software, you can redistribute it and/or modify
144 it under the same terms as Perl itself.