App.pm

filter: Statementstmt 89.6% 69 / 77 Branchbran 88.8% 16 / 18 Conditioncond 62.5% 15 / 24 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 88.2% 15 / 17 Podpod 83.3% 5 / 6 totaltotal 80.2% 126 / 157 CC 19 SCAR 24.2
CC
19
Cov
84%
new_with_command
20.3
app_command_register
6.0
app_namespace
2.0
CRAP 11.2
« App/Message/BlockColor.pm ↑ Summary App/Exporter.pm »
1 # ============================================================================«
2 package MooseX::App;
3 # ============================================================================«
4  
5 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 our $AUTHORITY = 'cpan:MAROS';
11 11 our $VERSION = '1.43';
12  
13 11 ▶use MooseX::App::Meta::Role::Attribute::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use MooseX::App::Exporter qw(app_usage app_description app_base app_fuzzy app_strict app_prefer_commandline app_permute option parameter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use MooseX::App::Message::Envelope;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods(
20 with_meta => [ qw(app_usage app_description app_namespace app_exclude app_base app_fuzzy app_command_name app_command_register app_strict app_prefer_commandline option parameter app_permute) ],
21 also => [ 'Moose' ],
22 as_is => [ 'new_with_command' ],
23 install => [ 'unimport','init_meta' ],
24 );
25  
26 12 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
27 12 my ( $class, @plugins ) = @_;
28  
29 # Get caller
30 12 my ($caller_class) = caller();
31  
32 # Process plugins
33 12 MooseX::App::Exporter->process_plugins($caller_class,@plugins);
34  
35 # Call Moose-Exporter generated importer
36 12 return $class->$IMPORT( { into => $caller_class } );
37 }
38  
39 12 ▶sub init_meta {
Subroutine init_meta: called CC=1 SCAR=0.0
Pod undocumented
40 12 my ($class,%args) = @_;
41  
42 # Get required roles and metaroles
43 12 $args{roles} = ['MooseX::App::Role::Base'];
44 $args{metaroles} = {
45 12 class => [
46 'MooseX::App::Meta::Role::Class::Base',
47 'MooseX::App::Meta::Role::Class::Documentation'
48 ],
49 attribute => [
50 'MooseX::App::Meta::Role::Attribute::Option'
51 ],
52 };
53  
54 12 return MooseX::App::Exporter->process_init_meta(%args);
55 }
56  
57 3 ▶sub app_command_name(&) {
Subroutine app_command_name: called CC=1 SCAR=0.0
Pod documented
58 3 my ( $meta, $namesub ) = @_;
59 3 return $meta->app_command_name($namesub);
60 }
61  
62 0 ▶sub app_command_register(%) {
Subroutine app_command_register: not called CC=2 SCAR=17.9
Pod documented
63 0 my ( $meta, %commands ) = @_;
64  
65 0 foreach my $command (keys %commands) {
66 0 $meta->command_register($command,$commands{$command});
67 }
68 0 return;
69 }
70  
71 0 ▶sub app_namespace(@) {
Subroutine app_namespace: not called CC=1 SCAR=6.9
Pod documented
72 0 my ( $meta, @namespaces ) = @_;
73 0 return $meta->app_namespace( \@namespaces );
74 }
75  
76 3 ▶sub app_exclude(@) {
Subroutine app_exclude: called CC=1 SCAR=0.0
Pod documented
77 3 my ( $meta, @namespaces ) = @_;
78 3 return $meta->app_exclude( \@namespaces );
79 }
80  
81 71 ▶sub new_with_command {
Subroutine new_with_command: called CC=18 SCAR=30.1
Pod documented
82 71 my ($class,@args) = @_;
83  
84 71 ▶ Moose->throw_error('new_with_command is a class method')
Branch: 1 branch
BranchTrueFalseTotal
if not defined $class or builtin::blessed($class) 1 70 71
Condition66%2/3
not defined $class or builtin::blessed($class)
l!l&&r!l&&!r
0170
MC/DC50%1/2
not defined $class or builtin::blessed($class)
not defined $class builtin::blessed($class)
Truth table66%2/3
not(A) or B
A= not defined $classB= builtin::blessed($class)
ABresult
1X1
011
000
85 if ! defined $class || blessed($class);
86  
87 70 my $meta = $class->meta;
88 70 my $metameta = $meta->meta;
89  
90 # Sanity check
91 70 ▶ Moose->throw_error('new_with_command may only be called from the application base package:'.$class)
Branch: 1 branch
BranchTrueFalseTotal
if $metameta->does_role("MooseX::App::Meta::Role::Class::Command") or not $metameta->does_role("MooseX::App::Meta::Role::Class::Base") 1 69 70
Condition66%2/3
$metameta->does_role("MooseX::App::Meta::Role::Class::Command") or not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
l!l&&r!l&&!r
1069
MC/DC50%1/2
$metameta->does_role("MooseX::App::Meta::Role::Class::Command") or not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
$metameta->does_role("MooseX::App::Meta::Role::Class::Command") not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
Truth table66%2/3
A or not(B)
A= $metameta->does_role("MooseX::App::Meta::Role::Class::Command")B= not $metameta->does_role("MooseX::App::Meta::Role::Class::Base")
ABresult
1X1
011
000
92 if $metameta->does_role('MooseX::App::Meta::Role::Class::Command')
93 || ! $metameta->does_role('MooseX::App::Meta::Role::Class::Base');
94  
95 $meta->command_check()
96 69 ▶ if $ENV{APP_DEVELOPER} || $ENV{HARNESS_ACTIVE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"APP_DEVELOPER"} or $ENV{"HARNESS_ACTIVE"} 69 0 69
Condition33%1/3
$ENV{"APP_DEVELOPER"} or $ENV{"HARNESS_ACTIVE"}
l!l&&r!l&&!r
0690
MC/DC0%0/2
$ENV{"APP_DEVELOPER"} or $ENV{"HARNESS_ACTIVE"}
$ENV{"APP_DEVELOPER"} $ENV{"HARNESS_ACTIVE"}
Truth table33%1/3
A or B
A= $ENV{"APP_DEVELOPER"}B= $ENV{"HARNESS_ACTIVE"}
ABresult
1X1
011
000
97  
98 # Extra args
99 69 my %args;
100 69 ▶ if (scalar @args == 1
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1 and ref $args[0] eq 'HASH') { } 0 69 69
elsif (scalar @args % 2 == 0) { } 68 1 69
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "HASH"
!ll&&!rl&&r
6900
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "HASH"
scalar @args == 1 ref $args[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "HASH"
ABresult
0X0
100
111
101 && ref($args[0]) eq 'HASH' ) {
102 0 %args = %{$args[0]};
103 } elsif (scalar @args % 2 == 0) {
104 68 %args = @args;
105 } else {
106 1 Moose->throw_error('new_with_command got invalid extra arguments');
107 }
108  
109 # Get ARGV
110 68 my $argv = delete $args{ARGV};
111 68 my $parsed_argv;
112 68 ▶ if (defined $argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv) { } 7 61 68
113 7 $parsed_argv = MooseX::App::ParsedArgv->new( argv => $argv );
114 } else {
115 61 $parsed_argv = MooseX::App::ParsedArgv->instance();
116 }
117  
118 68 my $first_argv = $parsed_argv->first_argv;
119  
120 # Requested help
121 68 ▶ if (defined $first_argv
Branch: 2 branches
BranchTrueFalseTotal
if (defined $first_argv and lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/) { } 2 66 68
elsif (not defined $first_argv or $first_argv =~ /^\s*$/ or $first_argv =~ /^-{1,2}\w/) { } 2 64 66
Condition100%3/3
defined $first_argv and lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
!ll&&!rl&&r
2642
MC/DC100%2/2
defined $first_argv and lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
defined $first_argv lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
Truth table100%3/3
A and B
A= defined $first_argvB= lc($first_argv) =~ /^(help|h|\?|usage|-h|--help|-\?|--usage)$/
ABresult
0X0
100
111
122 && lc($first_argv) =~ m/^(help|h|\?|usage|-h|--help|-\?|--usage)$/) {
123 2 return MooseX::App::Message::Envelope->new(
124 $meta->command_usage_global(),
125 );
126 # No args
127 ▶ } elsif (! defined $first_argv
Condition66%4/6
not defined $first_argv or $first_argv =~ /^\s*$/ or $first_argv =~ /^-{1,2}\w/
l!l&&r!l&&!r
2064
not defined $first_argv or $first_argv =~ /^\s*$/
l!l&&r!l&&!r
2064
MC/DC33%1/3
not defined $first_argv or $first_argv =~ /^\s*$/ or $first_argv =~ /^-{1,2}\w/
not defined $first_argv $first_argv =~ /^\s*$/ $first_argv =~ /^-{1,2}\w/
Truth table50%2/4
not(A) or B or C
A= not defined $first_argvB= $first_argv =~ /^\s*$/C= $first_argv =~ /^-{1,2}\w/
ABCresult
1XX1
01X1
0011
0000
128 || $first_argv =~ m/^\s*$/
129 || $first_argv =~ m/^-{1,2}\w/) {
130 2 return MooseX::App::Message::Envelope->new(
131 $meta->command_message(
132 header => "Missing command", # LOCALIZE
133 type => "error",
134 ),
135 $meta->command_usage_global(),
136 127, # exitcode
137 );
138 # Looks like a command
139 } else {
140 64 my $return = $meta->command_find();
141  
142 # Nothing found
143 64 ▶ if (blessed $return
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($return) and $return->isa('MooseX::App::Message::Block')) { } 2 62 64
Condition66%2/3
builtin::blessed($return) and $return->isa("MooseX::App::Message::Block")
!ll&&!rl&&r
6202
MC/DC50%1/2
builtin::blessed($return) and $return->isa("MooseX::App::Message::Block")
builtin::blessed($return) $return->isa("MooseX::App::Message::Block")
Truth table66%2/3
A and B
A= builtin::blessed($return)B= $return->isa("MooseX::App::Message::Block")
ABresult
0X0
100
111
144 && $return->isa('MooseX::App::Message::Block')) {
145 2 return MooseX::App::Message::Envelope->new(
146 $return,
147 $meta->command_usage_global(),
148 127, # exitcode
149 );
150 # One command found
151 } else {
152 62 my $command_class = $meta->command_get($return);
153 62 return $class->initialize_command_class($command_class,%args);
154 }
155 }
156 }
157  
158  
159 11 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
160 11 1;
161  
162 __END__
« App/Message/BlockColor.pm ↑ Summary App/Exporter.pm »