blib/lib/Circle/Command.pm

filter: Statementstmt 17.4% 11 / 63 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 18.7% 3 / 16 Podpod 0.0% 0 / 12 totaltotal 10.4% 14 / 134 SCAR 51.4
CC
15
Cov
11%
_find_commands
156.0
desc
6.0
args
6.0
CRAP 171.2
« blib/lib/Circle/Ruleable.pm ↑ Summary blib/lib/Circle/Rule/Chain.pm »
1 # You may distribute under the terms of the GNU General Public License
2 #
3 # (C) Paul Evans, 2008-2014 -- leonerd@leonerd.org.uk
4  
5 package Circle::Command;
6  
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Attribute::Storage qw( get_subattrs get_subattr find_subs_with_attr );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 require mro;
12  
13 sub _find_commands
14 {
15 0 ▶ my ( $obj, $cinv, $containedby ) = @_;
Subroutine _find_commands: not called CC=12 SCAR=50.5
16  
17 0 my @ret;
18 my %commands;
19  
20 0 ▶ while( $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 0 0 0
21 0 my %subs = find_subs_with_attr( mro::get_linear_isa( ref $obj ), "Command_description",
22 matching => qr/^command_/,
23 );
24  
25 0 foreach my $name ( keys %subs ) {
26 0 ( my $commandname = $name ) =~ s/^command_//;
27 0 my $cv = $subs{$name};
28  
29 0 ▶ next if $commands{$commandname};
Branch: 1 branch
BranchTrueFalseTotal
if $commands{$commandname} 0 0 0
30  
31 0 my $subof = get_subattr( $cv, "Command_subof" );
32 0 ▶ next if $containedby and !$subof or
Branch: 1 branch
BranchTrueFalseTotal
if $containedby and not $subof or not $containedby and $subof or $containedby and $subof and $containedby ne $subof 0 0 0
Condition0%0/18
$containedby and not $subof or not $containedby and $subof or $containedby and $subof and $containedby ne $subof
l!l&&r!l&&!r
000
$containedby and not $subof or not $containedby and $subof
l!l&&r!l&&!r
000
$containedby and not $subof
!ll&&!rl&&r
000
not $containedby and $subof
!ll&&!rl&&r
000
$containedby and $subof and $containedby ne $subof
!ll&&!rl&&r
000
$containedby and $subof
!ll&&!rl&&r
000
MC/DC0%0/7
$containedby and not $subof or not $containedby and $subof or $containedby and $subof and $containedby ne $subof
$containedby not $subof not $containedby $subof $containedby $subof $containedby ne $subof
Truth table0%0/19
A and not(B) or not(C) and D or E and F and G
A= $containedbyB= not $subofC= not $containedbyD= $subofE= $containedbyF= $subofG= $containedby ne $subof
ABCDEFGresult
11XXXXX1
0X11XXX1
1011XXX1
0X0X1111
0X101111
100X1111
10101111
0X0X0XX0
0X0X10X0
0X0X1100
0X100XX0
0X1010X0
0X101100
100X0XX0
100X10X0
100X1100
10100XX0
101010X0
10101100
33 !$containedby and $subof or
34 $containedby and $subof and $containedby ne $subof;
35  
36 0 my $attrs = get_subattrs( $cv );
37  
38 0 $commands{$commandname} = 1;
39 0 push @ret, __PACKAGE__->new( %$attrs,
40 name => $commandname,
41 obj => $obj,
42 cv => $cv,
43 );
44 }
45  
46 # Collect in parent too
47 0 ▶ $obj = $obj->can( "commandable_parent" ) && $obj->commandable_parent( $cinv );
Condition0%0/3
$obj->can('commandable_parent') && $obj->commandable_parent($cinv)
!ll&&!rl&&r
000
MC/DC0%0/2
$obj->can('commandable_parent') && $obj->commandable_parent($cinv)
$obj->can('commandable_parent') $obj->commandable_parent($cinv)
Truth table0%0/3
A && B
A= $obj->can('commandable_parent')B= $obj->commandable_parent($cinv)
ABresult
0X0
100
111
48 }
49  
50 0 return @ret;
51 }
52  
53 sub root_commands
54 {
55 0 ▶ my $class = shift;
Subroutine root_commands: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ( $cinv ) = @_;
57  
58 0 return map { $_->name => $_ } _find_commands( $cinv->invocant, $cinv, undef );
59 }
60  
61 # Object stuff
62  
63 sub new
64 {
65 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my %attrs = @_;
67  
68 0 $attrs{name} =~ s/_/ /g;
69  
70 0 return bless \%attrs, $class;
71 }
72  
73 sub sub_commands
74 {
75 0 ▶ my $self = shift;
Subroutine sub_commands: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ( $cinv ) = @_;
77  
78 0 return map { $_->shortname => $_ } _find_commands( $cinv->invocant, $cinv, $self->name );
79 }
80  
81 sub name
82 {
83 0 ▶ my $self = shift; return $self->{name};
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
84 }
85  
86 sub shortname
87 {
88 0 ▶ my $self = shift;
Subroutine shortname: not called CC=1 SCAR=6.9
Pod undocumented
89 0 ( split m/ /, $self->name )[-1];
90 }
91  
92 sub is_default
93 {
94 0 ▶ my $self = shift; return $self->{Command_default};
Subroutine is_default: not called CC=1 SCAR=6.9
Pod undocumented
95 }
96  
97 sub desc
98 {
99 0 ▶ my $self = shift; return $self->{Command_description}[0] || "[no description]";
Subroutine desc: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$self->{'Command_description'}[0] || '[no description]'
l!l
00
MC/DC0%0/1
$self->{'Command_description'}[0] || '[no description]'
$self->{'Command_description'}[0]
Truth table0%0/2
A
A= $self->{'Command_description'}[0]
Aresult
11
00
100 }
101  
102 sub detail
103 {
104 0 ▶ my $self = shift; return $self->{Command_description}[1];
Subroutine detail: not called CC=1 SCAR=6.9
Pod undocumented
105 }
106  
107 sub args
108 {
109 0 ▶ my $self = shift;
Subroutine args: not called CC=2 SCAR=17.9
Pod undocumented
110 0 ▶ return unless $self->{Command_arg};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Command_arg"} 0 0 0
111 0 return @{ $self->{Command_arg} };
112 }
113  
114 sub opts
115 {
116 0 ▶ my $self = shift;
Subroutine opts: not called CC=1 SCAR=6.9
Pod undocumented
117 0 return $self->{Command_opt};
118 }
119  
120 sub default_sub
121 {
122 0 ▶ my $self = shift;
Subroutine default_sub: not called CC=2 SCAR=17.9
Pod undocumented
123 0 my ( $cinv ) = @_;
124  
125 0 my %subs = $self->sub_commands( $cinv );
126 0 my @defaults = grep { $_->is_default } values %subs;
127  
128 0 ▶ return $defaults[0] if @defaults == 1; # Only if it's unique
Branch: 1 branch
BranchTrueFalseTotal
if @defaults == 1 0 0 0
129 0 return;
130 }
131  
132 sub invoke
133 {
134 0 ▶ my $self = shift; $self->{cv}->( $self->{obj}, @_ );
Subroutine invoke: not called CC=1 SCAR=6.9
Pod undocumented
135 }
136  
137 4 0x55AA;
« blib/lib/Circle/Ruleable.pm ↑ Summary blib/lib/Circle/Rule/Chain.pm »