lib/Catalyst/ScriptRole.pm

filter: Statementstmt 86.5% 45 / 52 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.4% 13 / 17 Podpod 100% 2 / 2 totaltotal 84.9% 62 / 73 CC 2 SCAR 2.1
CC
2
Cov
87%
_getopt_spec_warnings
2.0
print_usage_text
2.0
_run_application
2.0
CRAP 1.2
« lib/Catalyst/Component/ApplicationAttribute.pm ↑ Summary lib/Catalyst/DispatchType.pm »
1 package Catalyst::ScriptRole;
2 10 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use MooseX::Getopt;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Catalyst::EngineLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Catalyst::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use namespace::clean -except => [ 'meta' ];
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 subtype 'Catalyst::ScriptRole::LoadableClass',
11 as 'ClassName';
12 coerce 'Catalyst::ScriptRole::LoadableClass',
13 from 'Str',
14 0 ▶ via { Catalyst::Utils::ensure_class_loaded($_); $_ };
Subroutine __ANON__: not called CC=1 SCAR=2.6
15  
16 10 with 'MooseX::Getopt' => {
17 -version => 0.48,
18 -excludes => [qw/
19 _getopt_spec_warnings
20 _getopt_spec_exception
21 print_usage_text
22 /],
23 };
24  
25 10 has application_name => (
26 traits => ['NoGetopt'],
27 isa => 'Str',
28 is => 'ro',
29 required => 1,
30 );
31  
32 10 has loader_class => (
33 isa => 'Catalyst::ScriptRole::LoadableClass',
34 is => 'ro',
35 coerce => 1,
36 default => 'Catalyst::EngineLoader',
37 documentation => 'The class to use to detect and load the PSGI engine',
38 );
39  
40 has _loader => (
41 isa => 'Plack::Loader',
42 22 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 22 my $self = shift;
44 22 $self->loader_class->new(application_name => $self->application_name);
45 },
46 10 handles => {
47 load_engine => 'load',
48 autoload_engine => 'auto',
49 },
50 lazy => 1,
51 );
52  
53 0 ▶sub _getopt_spec_exception {}
Subroutine _getopt_spec_exception: not called CC=1 SCAR=0.0
54  
55 0 ▶sub _getopt_spec_warnings {
Subroutine _getopt_spec_warnings: not called CC=1 SCAR=6.9
56 0 shift;
57 0 warn @_;
58 }
59  
60 0 ▶sub print_usage_text {
Subroutine print_usage_text: not called CC=1 SCAR=6.9
Pod documented
61 0 my $self = shift;
62 0 pod2usage();
63 0 exit 0;
64 }
65  
66 19 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod documented
67 19 my $self = shift;
68 19 $self->_run_application;
69 }
70  
71 41 ▶sub _application_args {
Subroutine _application_args: called CC=1 SCAR=0.0
72 41 my $self = shift;
73 return {
74 41 argv => $self->ARGV,
75 extra_argv => $self->extra_argv,
76 }
77 }
78  
79 4 ▶sub _plack_loader_args {
Subroutine _plack_loader_args: called CC=1 SCAR=0.0
80 4 my $self = shift;
81 4 my @app_args = $self->_application_args;
82 4 return (port => $app_args[0]);
83 }
84  
85 2 ▶sub _plack_engine_name {}
Subroutine _plack_engine_name: called CC=1 SCAR=0.0
86  
87 37 ▶sub _run_application {
Subroutine _run_application: called CC=2 SCAR=6.9
88 37 my $self = shift;
89 37 my $app = $self->application_name;
90 37 Catalyst::Utils::ensure_class_loaded($app);
91 37 my $server;
92 37 ▶ if (my $e = $self->_plack_engine_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $self->_plack_engine_name) { } 35 2 37
93 35 $server = $self->load_engine($e, $self->_plack_loader_args);
94 }
95 else {
96 2 $server = $self->autoload_engine($self->_plack_loader_args);
97 }
98 37 $app->run($self->_application_args, $server);
99 }
100  
101 10 1;
102  
103 =head1 NAME
104  
105 Catalyst::ScriptRole - Common functionality for Catalyst scripts.
106  
107 =head1 SYNOPSIS
108  
109 package MyApp::Script::Foo;
110 use Moose;
111 use namespace::autoclean;
112  
113 with 'Catalyst::ScriptRole';
114  
115 sub _application_args { ... }
116  
117 =head1 DESCRIPTION
118  
119 Role with the common functionality of Catalyst scripts.
120  
121 =head1 METHODS
122  
123 =head2 run
124  
125 The method invoked to run the application.
126  
127 =head2 print_usage_text
128  
129 Prints out the usage text for the script you tried to invoke.
130  
131 =head1 ATTRIBUTES
132  
133 =head2 application_name
134  
135 The name of the application class, e.g. MyApp
136  
137 =head1 SEE ALSO
138  
139 L<Catalyst>
140  
141 L<MooseX::Getopt>
142  
143 =head1 AUTHORS
144  
145 Catalyst Contributors, see Catalyst.pm
146  
147 =head1 COPYRIGHT
148  
149 This library is free software, you can redistribute it and/or modify
150 it under the same terms as Perl itself.
151  
152 =cut
« lib/Catalyst/Component/ApplicationAttribute.pm ↑ Summary lib/Catalyst/DispatchType.pm »