App/Exporter.pm

filter: Statementstmt 94.2% 131 / 139 Branchbran 64.7% 22 / 34 Conditioncond 60.0% 9 / 15 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 88.4% 23 / 26 Podpod 0.0% 0 / 13 totaltotal 79.5% 187 / 235 CC 34 SCAR 22.9
CC
34
Cov
86%
_handle_attribute
19.4
process_init_meta
14.2
__ANON__
6.0
CRAP 9.9
« App.pm ↑ Summary App/ParsedArgv/Element.pm »
1 # ============================================================================
2 package MooseX::App::Exporter;
3 # ============================================================================
4  
5 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use MooseX::App::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use MooseX::App::ParsedArgv;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 16 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 16 my %PLUGIN_SPEC;
16  
17 39 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
18 39 my ( $class, @imports ) = @_;
19  
20 39 my $caller_class = caller();
21  
22 39 my $caller_stash = Package::Stash->new($caller_class);
23 39 my $exporter_stash = Package::Stash->new(__PACKAGE__);
24  
25 39 foreach my $import (@imports) {
26 263 my $symbol = $exporter_stash->get_symbol('&'.$import);
27 263 ▶ Carp::confess(sprintf('Symbol %s not defined in %s',$import,__PACKAGE__))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $symbol 0 263 263
28 unless defined $symbol;
29 263 $caller_stash->add_symbol('&'.$import, $symbol);
30 }
31  
32 39 return;
33 }
34  
35 15 ▶sub parameter {
Subroutine parameter: called CC=1 SCAR=0.0
Pod undocumented
36 15 my ($meta,$name,@rest) = @_;
37 15 return _handle_attribute($meta,$name,'parameter',@rest);
38 }
39  
40 105 ▶sub option {
Subroutine option: called CC=1 SCAR=0.0
Pod undocumented
41 105 my ($meta,$name,@rest) = @_;
42 105 return _handle_attribute($meta,$name,'option',@rest);
43 }
44  
45 120 ▶sub _handle_attribute {
Subroutine _handle_attribute: called CC=18 SCAR=29.7
46 120 my ($meta,$name,$type,@rest) = @_;
47  
48 120 ▶ Moose->throw_error('Usage: option \'name\' => ( key => value, ... )')
Branch: 1 branch
BranchTrueFalseTotal
if @rest % 2 == 1 0 120 120
49 if @rest % 2 == 1;
50  
51 120 my %info;
52 120 @info{qw(package file line)} = caller(2);
53  
54 120 my %attributes = ( definition_context => \%info, @rest );
55 120 ▶ my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $name eq 'ARRAY' ? : 2 118 120
56  
57 # We are in a command class
58 120 ▶ if (! $meta->isa('Moose::Meta::Role')
Branch: 1 branch
BranchTrueFalseTotal
if (not $meta->isa("Moose::Meta::Role") and $meta->meta->does_role("MooseX::App::Meta::Role::Class::Command")) 90 30 120
Condition100%3/3
not $meta->isa("Moose::Meta::Role") and $meta->meta->does_role("MooseX::App::Meta::Role::Class::Command")
!ll&&!rl&&r
62490
MC/DC100%2/2
not $meta->isa("Moose::Meta::Role") and $meta->meta->does_role("MooseX::App::Meta::Role::Class::Command")
not $meta->isa("Moose::Meta::Role") $meta->meta->does_role("MooseX::App::Meta::Role::Class::Command")
Truth table100%3/3
not(A) and B
A= not $meta->isa("Moose::Meta::Role")B= $meta->meta->does_role("MooseX::App::Meta::Role::Class::Command")
ABresult
0X0
100
111
59 && $meta->meta->does_role('MooseX::App::Meta::Role::Class::Command')) {
60  
61 # Get required extra traits for this class on first attrubute
62 90 ▶ unless ($meta->has_app_attribute_metaroles) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->has_app_attribute_metaroles) 29 61 90
63 # Find MooseX::App::Meta::Role::Class::Base in ISA
64 29 foreach my $parent ($meta->linearized_isa) {
65 94 ▶ if ($parent->meta->does_role('MooseX::App::Meta::Role::Class::Base')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->meta->does_role("MooseX::App::Meta::Role::Class::Base")) 0 94 94
66 0 $meta->app_attribute_metaroles([]);
67 0 last;
68 }
69 }
70 # Apply missing meta roles if required to do so
71 29 ▶ unless ($meta->has_app_attribute_metaroles) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->has_app_attribute_metaroles) 29 0 29
72 29 my @extra_classes;
73 29 my $name = $meta->name;
74 29 foreach my $class (keys %PLUGIN_SPEC) {
75 32 my @commands = $class->meta->command_classes;
76 32 ▶ if (first { $name eq $_ } @commands) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $name eq $_; } , @commands)) 29 3 32
77 29 my $attribute_metaclass = $class->meta->attribute_metaclass;
78 push @extra_classes,
79 4 map { $_->name }
80 35 grep { $_->name ne 'MooseX::App::Meta::Role::Attribute::Option' }
81 37 grep { ! $_->isa('Moose::Meta::Role::Composite') }
82 map {
83 29 ▶ $_->isa('Moose::Meta::Role::Composite') ?
Branch: 1 branch
BranchTrueFalseTotal
$_->isa('Moose::Meta::Role::Composite') ? : 2 31 33
84 $_->calculate_all_roles : $_
85 }
86 $attribute_metaclass->meta->calculate_all_roles_with_inheritance;
87 }
88 }
89  
90 29 $meta->app_attribute_metaroles_add(@extra_classes);
91 }
92 }
93  
94 90 ▶ $attributes{traits} ||= [];
Condition50%1/2
$attributes{"traits"} ||= []
l!l
090
MC/DC0%0/1
$attributes{"traits"} ||= []
$attributes{"traits"}
Truth table50%1/2
A
A= $attributes{"traits"}
Aresult
11
00
95 90 push(@{$attributes{traits}},$meta->app_attribute_metaroles_uniq);
96 }
97  
98 120 $attributes{'cmd_type'} = $type;
99 # Loop all attributes and check attribute traits
100 120 foreach my $attr (@$attrs) {
101 122 my %local_attributes = %attributes;
102 122 ▶ if ($attr =~ m/^\+(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^\+(.+)/) 1 121 122
103 1 my $meta_attribute = $meta->find_attribute_by_name($1);
104 1 ▶ unless ($meta_attribute->does('MooseX::App::Meta::Role::Attribute::Option')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta_attribute->does("MooseX::App::Meta::Role::Attribute::Option")) 1 0 1
105 1 ▶ $local_attributes{traits} ||= [];
Condition50%1/2
$local_attributes{"traits"} ||= []
l!l
01
MC/DC0%0/1
$local_attributes{"traits"} ||= []
$local_attributes{"traits"}
Truth table50%1/2
A
A= $local_attributes{"traits"}
Aresult
11
00
106 1 push @{$local_attributes{traits}},'MooseX::App::Meta::Role::Attribute::Option'
107 0 ▶ unless (first { $_ eq 'AppOption' || $_ eq 'MooseX::App::Meta::Role::Attribute::Option' }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "AppOption" or $_ eq "MooseX::App::Meta::Role::Attribute::Option" 0 0 0
108 1 ▶ @{$local_attributes{traits}});
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_ eq "AppOption" or $_ eq "MooseX::App::Meta::Role::Attribute::Option"; } , @{$local_attributes{"traits"};}) 1 0 1
109 }
110 }
111  
112 122 $meta->add_attribute($attr, %local_attributes);
113 }
114  
115 120 return;
116 }
117  
118 5 ▶sub app_prefer_commandline($) {
Subroutine app_prefer_commandline: called CC=1 SCAR=0.0
Pod undocumented
119 5 my ( $meta, $value ) = @_;
120 5 return $meta->app_prefer_commandline($value);
121 }
122  
123 5 ▶sub app_strict($) {
Subroutine app_strict: called CC=1 SCAR=0.0
Pod undocumented
124 5 my ( $meta, $value ) = @_;
125 5 return $meta->app_strict($value);
126 }
127  
128 1 ▶sub app_fuzzy($) {
Subroutine app_fuzzy: called CC=1 SCAR=0.0
Pod undocumented
129 1 my ( $meta, $value ) = @_;
130 1 return $meta->app_fuzzy($value);
131 }
132  
133 3 ▶sub app_permute($) {
Subroutine app_permute: called CC=1 SCAR=0.0
Pod undocumented
134 3 my ( $meta, $value ) = @_;
135 3 return $meta->app_permute($value);
136 }
137  
138 3 ▶sub app_base($) {
Subroutine app_base: called CC=1 SCAR=0.0
Pod undocumented
139 3 my ( $meta, $name ) = @_;
140 3 return $meta->app_base($name);
141 }
142  
143 18 ▶sub process_plugins {
Subroutine process_plugins: called CC=2 SCAR=6.9
Pod undocumented
144 18 my ($self,$caller_class,@plugins) = @_;
145  
146 # Loop all requested plugins
147 18 my @plugin_classes;
148 18 foreach my $plugin (@plugins) {
149 16 my $plugin_class = 'MooseX::App::Plugin::'.$plugin;
150  
151 # TODO eval plugin class
152 16 Class::Load::load_class($plugin_class);
153  
154 16 push (@plugin_classes,$plugin_class);
155 }
156  
157 # Store plugin spec
158 18 $PLUGIN_SPEC{$caller_class} = \@plugin_classes;
159 18 return;
160 }
161  
162 18 ▶sub process_init_meta {
Subroutine process_init_meta: called CC=13 SCAR=26.5
Pod undocumented
163 18 my ($self,%args) = @_;
164  
165 18 Moose->init_meta( %args );
166  
167 18 ▶ my $plugins = $PLUGIN_SPEC{$args{for_class}} || [];
Condition50%1/2
$PLUGIN_SPEC{$args{'for_class'}} || []
l!l
180
MC/DC0%0/1
$PLUGIN_SPEC{$args{'for_class'}} || []
$PLUGIN_SPEC{$args{'for_class'}}
Truth table50%1/2
A
A= $PLUGIN_SPEC{$args{'for_class'}}
Aresult
11
00
168 18 ▶ my $apply_metaroles = delete $args{metaroles} || {};
Condition50%1/2
delete $args{'metaroles'} || {}
l!l
180
MC/DC0%0/1
delete $args{'metaroles'} || {}
delete $args{'metaroles'}
Truth table50%1/2
A
A= delete $args{'metaroles'}
Aresult
11
00
169 18 ▶ my $apply_roles = delete $args{roles} || [];
Condition50%1/2
delete $args{'roles'} || []
l!l
180
MC/DC0%0/1
delete $args{'roles'} || []
delete $args{'roles'}
Truth table50%1/2
A
A= delete $args{'roles'}
Aresult
11
00
170  
171 # Add plugin roles
172 18 foreach my $plugin (@$plugins) {
173 16 push(@{$apply_roles},$plugin,{ -excludes => [ 'plugin_metaroles' ] } )
174 }
175  
176 # Add common role
177 18 push(@{$apply_roles},'MooseX::App::Role::Common')
178 18 ▶ unless first { $_ eq 'MooseX::App::Role::Common' } @{$apply_roles};
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_ eq "MooseX::App::Role::Common"; } , @{$apply_roles;}) 18 0 18
179  
180 # Process all plugins in the given order
181 18 foreach my $plugin_class (@{$plugins}) {
182 16 ▶ if ($plugin_class->can('plugin_metaroles')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin_class->can("plugin_metaroles")) 16 0 16
183 16 my ($metaroles) = $plugin_class->plugin_metaroles($args{for_class});
184 16 ▶ if (ref $metaroles eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $metaroles eq "HASH") 16 0 16
185 16 foreach my $type (keys %$metaroles) {
186 20 ▶ $apply_metaroles->{$type} ||= [];
Condition50%1/2
$apply_metaroles->{$type} ||= []
l!l
200
MC/DC0%0/1
$apply_metaroles->{$type} ||= []
$apply_metaroles->{$type}
Truth table50%1/2
A
A= $apply_metaroles->{$type}
Aresult
11
00
187 20 push (@{$apply_metaroles->{$type}},@{$metaroles->{$type}});
188 }
189 }
190 }
191 }
192  
193 # Add meta roles
194 Moose::Util::MetaRole::apply_metaroles(
195 for => $args{for_class},
196 18 class_metaroles => $apply_metaroles
197 );
198  
199 # Add class roles
200 18 Moose::Util::apply_all_roles($args{for_class},@{$apply_roles});
201  
202 # Init plugins
203 18 foreach my $plugin_class (@{$plugins}) {
204 16 ▶ if ($plugin_class->can('init_plugin')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin_class->can("init_plugin")) 0 16 16
205 0 $plugin_class->init_plugin($args{for_class});
206 }
207 }
208  
209 # Return meta
210 18 my $meta = $args{for_class}->meta;
211  
212 18 return $meta;
213 }
214  
215 19 ▶sub command_short_description($) {
Subroutine command_short_description: called CC=1 SCAR=0.0
Pod undocumented
216 19 my ( $meta, $description ) = @_;
217 19 return $meta->command_short_description($description);
218 }
219  
220 12 ▶sub command_long_description($) {
Subroutine command_long_description: called CC=1 SCAR=0.0
Pod undocumented
221 12 my ( $meta, $description ) = @_;
222 12 return $meta->command_long_description($description);
223 }
224  
225 0 ▶sub command_usage($) {
Subroutine command_usage: not called CC=1 SCAR=6.9
Pod undocumented
226 0 my ( $meta, $usage ) = @_;
227 0 return $meta->command_usage($usage);
228 }
229  
230 16 *app_description = \&command_long_description;
231 16 *app_usage = \&command_usage;
232  
233 0 ▶sub command_strict($) {
Subroutine command_strict: not called CC=1 SCAR=6.9
Pod undocumented
234 0 my ( $meta, $value ) = @_;
235 0 return $meta->command_strict($value);
236 }
237  
238 16 1;
« App.pm ↑ Summary App/ParsedArgv/Element.pm »