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' => {
20 _getopt_spec_exception
25 has application_name => (
26 traits => ['NoGetopt'],
33 isa => 'Catalyst::ScriptRole::LoadableClass',
36 default => 'Catalyst::EngineLoader',
37 documentation => 'The class to use to detect and load the PSGI engine',
41 isa => 'Plack::Loader',
44 $self->loader_class->new(application_name => $self->application_name);
47 load_engine => 'load',
48 autoload_engine => 'auto',
53 sub _getopt_spec_exception {}
55 sub _getopt_spec_warnings {
60 sub print_usage_text {
68 $self->_run_application;
71 sub _application_args {
75 extra_argv => $self->extra_argv,
79 sub _plack_loader_args {
81 my @app_args = $self->_application_args;
82 return (port => $app_args[0]);
85 sub _plack_engine_name {}
87 sub _run_application {
89 my $app = $self->application_name;
90 Class::MOP::load_class($app);
92 if (my $e = $self->_plack_engine_name ) {
93 $server = $self->load_engine($e, $self->_plack_loader_args);
96 $server = $self->autoload_engine($self->_plack_loader_args);
98 $app->run($self->_application_args, $server);
105 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
109 package MyApp::Script::Foo;
111 use namespace::autoclean;
113 with 'Catalyst::ScriptRole';
115 sub _application_args { ... }
119 Role with the common functionality of Catalyst scripts.
125 The method invoked to run the application.
127 =head2 print_usage_text
129 Prints out the usage text for the script you tried to invoke.
133 =head2 application_name
135 The name of the application class, e.g. MyApp
145 Catalyst Contributors, see Catalyst.pm
149 This library is free software, you can redistribute it and/or modify
150 it under the same terms as Perl itself.