Circle/Command.pm

filter: Statementstmt 79.6% 51 / 64 Branchbran 70.0% 7 / 10 Conditioncond 86.9% 20 / 23 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 75.0% 12 / 16 Podpod 0.0% 0 / 12 totaltotal 71.1% 96 / 135 CC 15 SCAR 18.2
CC
15
Cov
80%
_find_commands
12.0
desc
6.0
default_sub
6.0
CRAP 6.2
« Circle/Net.pm ↑ Summary Circle/Widget/Box.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 our $VERSION = '0.173320';
11  
12 4 ▶use Attribute::Storage qw( get_subattrs get_subattr find_subs_with_attr );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 require mro;
14  
15 sub _find_commands
16 12 ▶{
Subroutine _find_commands: called CC=12 SCAR=24.9
17 12 my ( $obj, $cinv, $containedby ) = @_;
18  
19 12 my @ret;
20 my %commands;
21  
22 12 ▶ while( $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 22 12 34
23 22 my %subs = find_subs_with_attr( mro::get_linear_isa( ref $obj ), "Command_description",
24 matching => qr/^command_/,
25 );
26  
27 22 foreach my $name ( keys %subs ) {
28 444 ( my $commandname = $name ) =~ s/^command_//;
29 444 my $cv = $subs{$name};
30  
31 444 ▶ next if $commands{$commandname};
Branch: 1 branch
BranchTrueFalseTotal
if $commands{$commandname} 12 432 444
32  
33 432 my $subof = get_subattr( $cv, "Command_subof" );
34 432 ▶ 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 342 90 432
Condition94%17/18
$containedby and not $subof or not $containedby and $subof or $containedby and $subof and $containedby ne $subof
l!l&&r!l&&!r
22411890
$containedby and not $subof or not $containedby and $subof
l!l&&r!l&&!r
13292208
$containedby and not $subof
!ll&&!rl&&r
174126132
not $containedby and $subof
!ll&&!rl&&r
1268292
$containedby and $subof and $containedby ne $subof
!ll&&!rl&&r
828118
$containedby and $subof
!ll&&!rl&&r
820126
MC/DC57%4/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 table26%5/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
35 !$containedby and $subof or
36 $containedby and $subof and $containedby ne $subof;
37  
38 90 my $attrs = get_subattrs( $cv );
39  
40 90 $commands{$commandname} = 1;
41 90 push @ret, __PACKAGE__->new( %$attrs,
42 name => $commandname,
43 obj => $obj,
44 cv => $cv,
45 );
46 }
47  
48 # Collect in parent too
49 22 ▶ $obj = $obj->can( "commandable_parent" ) && $obj->commandable_parent( $cinv );
Condition100%3/3
$obj->can('commandable_parent') && $obj->commandable_parent($cinv)
!ll&&!rl&&r
8410
MC/DC100%2/2
$obj->can('commandable_parent') && $obj->commandable_parent($cinv)
$obj->can('commandable_parent') $obj->commandable_parent($cinv)
Truth table100%3/3
A && B
A= $obj->can('commandable_parent')B= $obj->commandable_parent($cinv)
ABresult
0X0
100
111
50 }
51  
52 12 return @ret;
53 }
54  
55 sub root_commands
56 5 ▶{
Subroutine root_commands: called CC=1 SCAR=0.0
Pod undocumented
57 5 my $class = shift;
58 5 my ( $cinv ) = @_;
59  
60 5 return map { $_->name => $_ } _find_commands( $cinv->invocant, $cinv, undef );
61 }
62  
63 # Object stuff
64  
65 sub new
66 90 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
67 90 my $class = shift;
68 90 my %attrs = @_;
69  
70 90 $attrs{name} =~ s/_/ /g;
71  
72 90 return bless \%attrs, $class;
73 }
74  
75 sub sub_commands
76 7 ▶{
Subroutine sub_commands: called CC=1 SCAR=0.0
Pod undocumented
77 7 my $self = shift;
78 7 my ( $cinv ) = @_;
79  
80 7 return map { $_->shortname => $_ } _find_commands( $cinv->invocant, $cinv, $self->name );
81 }
82  
83 sub name
84 102 ▶{
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
85 102 my $self = shift; return $self->{name};
86 }
87  
88 sub shortname
89 8 ▶{
Subroutine shortname: called CC=1 SCAR=0.0
Pod undocumented
90 8 my $self = shift;
91 8 ( split m/ /, $self->name )[-1];
92 }
93  
94 sub is_default
95 0 ▶{
Subroutine is_default: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my $self = shift; return $self->{Command_default};
97 }
98  
99 sub desc
100 0 ▶{
Subroutine desc: not called CC=2 SCAR=17.9
Pod undocumented
101 0 ▶ my $self = shift; return $self->{Command_description}[0] || "[no description]";
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
102 }
103  
104 sub detail
105 0 ▶{
Subroutine detail: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my $self = shift; return $self->{Command_description}[1];
107 }
108  
109 sub args
110 5 ▶{
Subroutine args: called CC=2 SCAR=7.0
Pod undocumented
111 5 my $self = shift;
112 5 ▶ return unless $self->{Command_arg};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"Command_arg"} 0 5 5
113 5 return @{ $self->{Command_arg} };
114 }
115  
116 sub opts
117 5 ▶{
Subroutine opts: called CC=1 SCAR=0.0
Pod undocumented
118 5 my $self = shift;
119 5 return $self->{Command_opt};
120 }
121  
122 sub default_sub
123 0 ▶{
Subroutine default_sub: not called CC=2 SCAR=17.9
Pod undocumented
124 0 my $self = shift;
125 0 my ( $cinv ) = @_;
126  
127 0 my %subs = $self->sub_commands( $cinv );
128 0 my @defaults = grep { $_->is_default } values %subs;
129  
130 0 ▶ return $defaults[0] if @defaults == 1; # Only if it's unique
Branch: 1 branch
BranchTrueFalseTotal
if @defaults == 1 0 0 0
131 0 return;
132 }
133  
134 sub invoke
135 5 ▶{
Subroutine invoke: called CC=1 SCAR=0.0
Pod undocumented
136 5 my $self = shift; $self->{cv}->( $self->{obj}, @_ );
137 }
138  
139 4 0x55AA;
« Circle/Net.pm ↑ Summary Circle/Widget/Box.pm »