1 package Catalyst::ScriptRole;
4 use MooseX::Types::Moose qw/Str Bool/;
7 use namespace::autoclean;
9 with 'MooseX::Getopt' => {
12 _getopt_spec_exception
17 has application_name => (
18 traits => ['NoGetopt'],
28 documentation => 'Display this help and exit',
29 cmd_aliases => ['?', 'h'],
32 sub _getopt_spec_exception {}
34 sub _getopt_spec_warnings {
39 sub _getopt_full_usage {
47 $self->_getopt_full_usage if $self->help;
52 $self->_run_application;
55 sub _application_args {
59 sub _plack_loader_args {
60 my @app_args = shift->_application_args;
61 return (port => $app_args[0]);
64 sub _run_application {
66 my $app = $self->application_name;
67 Class::MOP::load_class($app);
69 if (my $e = $self->can('_plack_engine_name') ) {
70 $server = Plack::Loader->load($self->$e, $self->_plack_loader_args);
73 $server = Plack::Loader->auto($self->_plack_loader_args);
75 $app->run($server, $self->_application_args);
82 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
86 package MyApp::Script::Foo;
88 use namespace::autoclean;
90 with 'Catalyst::ScriptRole';
92 sub _application_args { ... }
96 Role with the common functionality of Catalyst scripts.
102 The method invoked to run the application.
106 =head2 application_name
108 The name of the application class, e.g. MyApp
118 Catalyst Contributors, see Catalyst.pm
122 This library is free software, you can redistribute it and/or modify
123 it under the same terms as Perl itself.