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' => {
19 _getopt_spec_exception
24 has application_name => (
25 traits => ['NoGetopt'],
32 isa => 'Catalyst::ScriptRole::LoadableClass',
35 default => 'Catalyst::EngineLoader',
36 documentation => 'The class to use to detect and load the PSGI engine',
40 isa => 'Plack::Loader',
43 $self->loader_class->new(application_name => $self->application_name);
46 load_engine => 'load',
47 autoload_engine => 'auto',
52 sub _getopt_spec_exception {}
54 sub _getopt_spec_warnings {
59 sub print_usage_text {
67 $self->_run_application;
70 sub _application_args {
74 extra_argv => $self->extra_argv,
78 sub _plack_loader_args {
80 my @app_args = $self->_application_args;
81 return (port => $app_args[0]);
84 sub _plack_engine_name {}
86 sub _run_application {
88 my $app = $self->application_name;
89 Class::MOP::load_class($app);
91 if (my $e = $self->_plack_engine_name ) {
92 $server = $self->load_engine($e, $self->_plack_loader_args);
95 $server = $self->autoload_engine($self->_plack_loader_args);
97 $app->run($self->_application_args, $server);
104 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
108 package MyApp::Script::Foo;
110 use namespace::autoclean;
112 with 'Catalyst::ScriptRole';
114 sub _application_args { ... }
118 Role with the common functionality of Catalyst scripts.
124 The method invoked to run the application.
128 =head2 application_name
130 The name of the application class, e.g. MyApp
140 Catalyst Contributors, see Catalyst.pm
144 This library is free software, you can redistribute it and/or modify
145 it under the same terms as Perl itself.