lib/TUI/Views/CommandSet.pm

filter: Statementstmt 90.5% 144 / 159 Branchbran 53.4% 31 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 27 / 30 Podpod 82.3% 14 / 17 totaltotal 81.8% 216 / 264 CC 37 SCAR 13.8
CC
37
Cov
81%
from
20.0
__ANON__
5.2
__ANON__
5.2
CRAP 4.0
« lib/TUI/Menus/Menu.pm ↑ Summary lib/TUI/Views/Palette.pm »
1 package TUI::Views::CommandSet;
2 # ABSTRACT: A class for managing command sets
3
4 95 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 95 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 95 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 95 our $VERSION = '2.000002';
9 95 $VERSION =~ tr/_//d;
10 95 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 95 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 95 our @EXPORT = qw(
14 TCommandSet
15 new_TCommandSet
16 );
17
18 95 ▶use TUI::toolkit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
19 :boolean
20 :utils
21 95 );
22 95 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 :is
24 :types
25 95 );
26
27 sub TCommandSet() { __PACKAGE__ }
28 0 ▶sub new_TCommandSet { __PACKAGE__->from(@_) }
Subroutine new_TCommandSet: not called CC=1 SCAR=6.9
Pod undocumented
29
30 24562 ▶my $loc = sub { # $int ($cmd)
Subroutine __ANON__: called CC=3 SCAR=11.3
31 24562 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 24562 24562
32 24562 ▶ assert ( is_PositiveOrZeroInt $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($_[0]) 0 24562 24562
33 24562 int( $_[0] / 8 ) % 32;
34 95 };
35
36 24562 ▶my $mask = sub { # $int ($cmd)
Subroutine __ANON__: called CC=3 SCAR=11.3
37 24562 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 24562 24562
38 24562 ▶ assert ( is_PositiveOrZeroInt $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($_[0]) 0 24562 24562
39 24562 1 << ( $_[0] % 8 );
40 95 };
41
42 472 ▶my $disable_cmd = sub { # void ($cmd)
Subroutine __ANON__: called CC=4 SCAR=14.2
43 472 my ( $self, $cmd ) = @_;
44 472 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 472 472
45 472 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 472 472
46 472 ▶ assert ( is_PositiveOrZeroInt $cmd );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($cmd) 0 472 472
47 472 $self->[ &$loc( $cmd ) ] &= ~ &$mask( $cmd );
48 472 return;
49 95 };
50
51 24074 ▶my $enable_cmd = sub { # void ($cmd)
Subroutine __ANON__: called CC=4 SCAR=14.2
52 24074 my ( $self, $cmd ) = @_;
53 24074 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 24074 24074
54 24074 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 24074 24074
55 24074 ▶ assert ( is_PositiveOrZeroInt $cmd );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($cmd) 0 24074 24074
56 24074 $self->[ &$loc( $cmd ) ] |= &$mask( $cmd );
57 24074 return;
58 95 };
59
60 2 ▶my $disable_cmd_set = sub { # void ($tc)
Subroutine __ANON__: called CC=5 SCAR=16.5
61 2 my ( $self, $tc ) = @_;
62 2 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 2 2
63 2 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 2 2
64 2 ▶ assert ( is_Object $tc );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($tc) 0 2 2
65 2 $self->[$_] &= ~$tc->[$_] for 0 .. 31;
66 2 return;
67 95 };
68
69 2 ▶my $enable_cmd_set = sub { # void ($tc)
Subroutine __ANON__: called CC=5 SCAR=16.5
70 2 my ( $self, $tc ) = @_;
71 2 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 2 2
72 2 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 2 2
73 2 ▶ assert ( is_Object $tc );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($tc) 0 2 2
74 2 $self->[$_] |= $tc->[$_] for 0 .. 31;
75 2 return;
76 95 };
77
78 97 ▶sub new { # $obj (%args)
Subroutine new: called CC=2 SCAR=7.2
Pod documented
79 97 state $sig = signature(
80 method => 1,
81 named => [
82 copy_from => Object, { optional => 1 }
83 ],
84 );
85 97 my ( $class, $args ) = $sig->( @_ );
86 97 my $self = bless [ ( 0 ) x 32 ], $class;
87 0 @$self = @{ $args->{copy_from} }
88 97 ▶ if exists $args->{copy_from};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"copy_from"} 0 97 97
89 97 return $self;
90 }
91
92 0 ▶sub from { # $obj (|$tc)
Subroutine from: not called CC=4 SCAR=30.0
Pod undocumented
93 0 state $sig = signature(
94 method => 1,
95 pos => [ Object, { optional => 1 } ],
96 );
97 0 my ( $class, @args ) = $sig->( @_ );
98 0 SWITCH: for ( scalar @args ) {
99 0 ▶ $_ == 0 and return $class->new();
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 and return $class->new 0 0 0
100 0 ▶ $_ == 1 and return $class->new( copy_from => $args[0] );
Branch: 1 branch
BranchTrueFalseTotal
$_ == 1 and return $class->new("copy_from", $args[0]) 0 0 0
101 }
102 0 return;
103 }
104
105 4 ▶sub clone { # $clone ()
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
106 4 state $sig = signature(
107 method => 1,
108 pos => [],
109 );
110 4 my ( $self ) = $sig->( @_ );
111 4 my @data = @$self;
112 4 return bless [ @data ], ref $self;
113 }
114
115 16 ▶sub has { # $bool ($cmd)
Subroutine has: called CC=1 SCAR=0.0
Pod documented
116 16 state $sig = signature(
117 method => Object,
118 pos => [PositiveOrZeroInt],
119 );
120 16 my ( $self, $cmd ) = $sig->( @_ );
121 16 return ( $self->[ &$loc( $cmd ) ] & &$mask( $cmd ) ) != 0;
122 }
123
124 474 ▶sub disableCmd { # void ($cmd|$tc)
Subroutine disableCmd: called CC=2 SCAR=6.9
Pod documented
125 474 state $sig = signature(
126 method => Object,
127 pos => [Defined],
128 );
129 474 my ( $self, $arg ) = $sig->( @_ );
130 474 ▶ ref $arg
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 2 472 474
131 ? goto &$disable_cmd_set
132 : goto &$disable_cmd;
133 }
134
135 24076 ▶sub enableCmd { # void ($cmd|$tc)
Subroutine enableCmd: called CC=2 SCAR=6.9
Pod documented
136 24076 state $sig = signature(
137 method => Object,
138 pos => [Defined],
139 );
140 24076 my ( $self, $arg ) = $sig->( @_ );
141 24076 ▶ ref $arg
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 2 24074 24076
142 ? goto &$enable_cmd_set
143 : goto &$enable_cmd;
144 }
145
146 2 ▶sub isEmpty { # $bool ()
Subroutine isEmpty: called CC=3 SCAR=11.0
Pod documented
147 2 state $sig = signature(
148 method => Object,
149 pos => [],
150 );
151 2 my ( $self ) = $sig->( @_ );
152 2 for ( 0 .. 31 ) {
153 34 ▶ return false if $self->[$_] != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->[$_] != 0 1 33 34
154 }
155 1 return true;
156 }
157
158 2 ▶sub intersect { # $tc ($tc1, $tc2, |$wap)
Subroutine intersect: called CC=2 SCAR=7.0
Pod documented
159 2 state $sig = signature(
160 pos => [Object, Object, Bool, { optional => 1 }],
161 );
162 2 my ( $tc1, $tc2, $swap ) = $sig->( @_ );
163 2 ▶ ( $tc1, $tc2 ) = ( $tc2, $tc1 ) if $swap;
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
164 2 my $temp = $tc1->clone();
165 2 $temp->intersect_assign( $tc2 );
166 2 return $temp;
167 }
168
169 2 ▶sub union { # $tc ($tc1, $tc2, |$wap)
Subroutine union: called CC=2 SCAR=7.0
Pod documented
170 2 state $sig = signature(
171 pos => [Object, Object, Bool, { optional => 1 }],
172 );
173 2 my ( $tc1, $tc2, $swap ) = $sig->( @_ );
174 2 ▶ ( $tc1, $tc2 ) = ( $tc2, $tc1 ) if $swap;
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
175 2 my $temp = $tc1->clone();
176 2 $temp->union_assign( $tc2 );
177 2 return $temp;
178 }
179
180 6 ▶sub equal { # $bool ($tc1, $tc2, |$wap)
Subroutine equal: called CC=3 SCAR=11.0
Pod documented
181 6 state $sig = signature(
182 pos => [Object, Object, Bool, { optional => 1 }],
183 );
184 6 my ( $tc1, $tc2, $swap ) = $sig->( @_ );
185 6 for ( 0 .. 31 ) {
186 99 ▶ return false if $tc1->[$_] != $tc2->[$_];
Branch: 1 branch
BranchTrueFalseTotal
if $tc1->[$_] != $tc2->[$_] 3 96 99
187 }
188 3 return true;
189 }
190
191 3 ▶sub not_equal { # $bool ($tc1, $tc2, |$wap)
Subroutine not_equal: called CC=1 SCAR=0.0
Pod documented
192 3 state $sig = signature(
193 pos => [Object, Object, Bool, { optional => 1 }],
194 );
195 3 my ( $tc1, $tc2, $swap ) = $sig->( @_ );
196 3 return !equal( $tc1, $tc2 );
197 }
198
199 2 ▶sub include { # $self ($cmd|$tc, |$wap)
Subroutine include: called CC=2 SCAR=7.0
Pod documented
200 2 state $sig = signature(
201 method => Object,
202 pos => [Defined, Bool, { optional => 1 }],
203 );
204 2 my ( $self, $other, $swap ) = $sig->( @_ );
205 2 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
206 2 $self->enableCmd( $other );
207 2 return $self;
208 }
209
210 2 ▶sub exclude { # $self ($cmd|$tc, |$wap)
Subroutine exclude: called CC=2 SCAR=7.0
Pod documented
211 2 state $sig = signature(
212 method => Object,
213 pos => [Defined, Bool, { optional => 1 }],
214 );
215 2 my ( $self, $other, $swap ) = $sig->( @_ );
216 2 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
217 2 $self->disableCmd( $other );
218 2 return $self;
219 }
220
221 2 ▶sub intersect_assign { # $self ($tc, |$wap)
Subroutine intersect_assign: called CC=3 SCAR=11.0
Pod documented
222 2 state $sig = signature(
223 method => Object,
224 pos => [Object, Bool, { optional => 1 }],
225 );
226 2 my ( $self, $tc, $swap ) = $sig->( @_ );
227 2 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
228 2 $self->[$_] &= $tc->[$_] for 0 .. 31;
229 2 return $self;
230 }
231
232 2 ▶sub union_assign { # $self ($tc, |$wap)
Subroutine union_assign: called CC=3 SCAR=11.0
Pod documented
233 2 state $sig = signature(
234 method => Object,
235 pos => [Object, Bool, { optional => 1 }],
236 );
237 2 my ( $self, $tc, $swap ) = $sig->( @_ );
238 2 ▶ assert ( not $swap );
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 2 2
239 2 $self->[$_] |= $tc->[$_] for 0 .. 31;
240 2 return $self;
241 }
242
243 0 ▶sub dump { # $str ()
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
244 0 state $sig = signature(
245 method => Object,
246 pos => [],
247 );
248 0 my ( $self ) = $sig->( @_ );
249 0 my $dump = "$self=";
250 0 $dump .= join ':' => map { sprintf("%02x", $self->[$_]) } 0 .. 31;
251 0 $dump .= "\n";
252 0 return $dump;
253 }
254
255 use overload
256 95 ▶ '+=' => \&include,
Subroutine BEGIN: called CC=1 SCAR=0.0
257 '-=' => \&exclude,
258 '&=' => \&intersect_assign,
259 '|=' => \&union_assign,
260 '&' => \&intersect,
261 '|' => \&union,
262 '==' => \&equal,
263 '!=' => \&not_equal,
264 95 fallback => 1;
265
266 95 1
267
268 __END__
« lib/TUI/Menus/Menu.pm ↑ Summary lib/TUI/Views/Palette.pm »