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 default => 'Catalyst::Engine::Loader',
30 documentation => 'The class to use to detect and load the PSGI engine',
34 isa => 'Plack::Loader',
36 shift->loader_class->new
39 load_engine => 'load',
40 autoload_engine => 'auto',
45 sub _getopt_spec_exception {}
47 sub _getopt_spec_warnings {
52 sub _getopt_full_usage {
60 $self->_run_application;
63 sub _application_args {
67 sub _plack_loader_args {
68 my @app_args = shift->_application_args;
69 return (port => $app_args[0]);
72 sub _run_application {
74 my $app = $self->application_name;
75 Class::MOP::load_class($app);
77 if (my $e = $self->can('_plack_engine_name') ) {
78 $server = $self->load_engine($self->$e, $self->_plack_loader_args);
81 $server = $self->autoload_engine($self->_plack_loader_args);
83 $app->run($self->_application_args, $server);
90 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
94 package MyApp::Script::Foo;
96 use namespace::autoclean;
98 with 'Catalyst::ScriptRole';
100 sub _application_args { ... }
104 Role with the common functionality of Catalyst scripts.
110 The method invoked to run the application.
114 =head2 application_name
116 The name of the application class, e.g. MyApp
126 Catalyst Contributors, see Catalyst.pm
130 This library is free software, you can redistribute it and/or modify
131 it under the same terms as Perl itself.