lib/TUI/ColorSel/ColorGroup.pm

filter: Statementstmt 96.4% 107 / 111 Branchbran 62.5% 20 / 32 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 88.8% 24 / 27 Podpod 75.0% 3 / 4 totaltotal 81.4% 158 / 194 CC 23 SCAR 14.6
CC
23
Cov
85%
__ANON__
10.2
__ANON__
8.1
__ANON__
4.1
CRAP 4.3
« lib/TUI/Drivers/Event.pm ↑ Summary lib/TUI/Dialogs/MultiCheckBoxes.pm »
1 package TUI::ColorSel::ColorGroup;
2 # ABSTRACT: linked color group definition used by color selection dialogs
3
4 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 7 our $VERSION = '2.000002';
9 7 $VERSION =~ tr/_//d;
10 7 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 7 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 our @EXPORT = qw(
14 TColorGroup
15 new_TColorGroup
16 );
17
18 7 ▶use Class::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Devel::StrictMode;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use if STRICT => 'Hash::Util';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use TUI::toolkit qw( :utils );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 Maybe
24 is_Object
25 :types
26 7 );
27
28 7 ▶use TUI::ColorSel::ColorItem;
Subroutine BEGIN: called CC=1 SCAR=0.0
29
30 7 struct TColorIndex => [
31 groupIndex => '$',
32 colorSize => '$',
33 colorIndex => '@',
34 ];
35
36 sub TColorGroup() { __PACKAGE__ }
37 1 ▶sub new_TColorGroup { __PACKAGE__->from(@_) }
Subroutine new_TColorGroup: called CC=1 SCAR=0.0
Pod documented
38
39 # public attributes
40 7 ▶our %HAS; BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 %HAS = (
42 0 ▶ name => sub { '' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 9 ▶ index => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 8 ▶ items => sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 6 ▶ next => sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 7 );
47 }
48
49 # predeclare private methods
50 my (
51 7 $add_color_item,
52 $add_color_group,
53 );
54
55 9 ▶sub new { # \$item (%args)
Subroutine new: called CC=2 SCAR=6.9
Pod documented
56 9 state $sig = signature(
57 method => 1,
58 named => [
59 name => Str, { alias => 'nm' },
60 items => Maybe[Object], { alias => 'itm', optional => 1 },
61 next => Maybe[Object], { alias => 'nxt', optional => 1 },
62 ],
63 );
64 9 my ( $class, $self ) = $sig->( @_ );
65 $self->{$_} = $HAS{$_}->()
66 9 for grep { not exists $self->{$_} } keys %HAS;
67 9 bless $self, $class;
68 9 Hash::Util::lock_keys( %$self ) if STRICT;
69 9 return $self;
70 }
71
72 1 ▶sub from { # $item ($nm, |$itm, |$nxt)
Subroutine from: called CC=1 SCAR=0.0
Pod undocumented
73 1 state $sig = signature(
74 method => 1,
75 pos => [
76 Str,
77 Maybe[Object], { optional => 1 },
78 Maybe[Object], { optional => 1 },
79 ],
80 );
81 1 my ( $class, @args ) = $sig->( @_ );
82 1 return $class->new( name => $args[0], items => $args[1], next => $args[2] );
83 }
84
85 0 ▶sub _add_color_item { goto &$add_color_item }
Subroutine _add_color_item: not called CC=1 SCAR=6.9
86 6 ▶$add_color_item = sub { # $g ($g, $i, |undef)
Subroutine __ANON__: called CC=9 SCAR=23.2
87 6 my ( $g, $i ) = @_;
88 6 ▶ assert ( @_ >= 2 && @_ <= 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 and @_ <= 3 0 6 6
Condition33%1/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
006
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
89 6 ▶ assert ( is_Object $g );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($g) 0 6 6
90 6 ▶ assert ( is_Object $i and $i->isa( TColorItem ) );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($i) and $i->isa("TUI::ColorSel::ColorItem") 0 6 6
Condition33%1/3
&is_Object($i) and $i->isa("TUI::ColorSel::ColorItem")
!ll&&!rl&&r
006
MC/DC0%0/2
&is_Object($i) and $i->isa("TUI::ColorSel::ColorItem")
&is_Object($i) $i->isa("TUI::ColorSel::ColorItem")
Truth table33%1/3
A and B
A= &is_Object($i)B= $i->isa("TUI::ColorSel::ColorItem")
ABresult
0X0
100
111
91 6 my $grp = $g;
92 $grp = $grp->{next}
93 6 ▶ while $grp->{next};
Branch: 1 branch
BranchTrueFalseTotal
$grp->{"next"} and do { $grp = $grp->{"next"} } 0 6 6
94
95 6 ▶ if ( !$grp->{items} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $grp->{'items'}) { } 2 4 6
96 2 $grp->{items} = $i;
97 }
98 else {
99 4 my $cur = $grp->{items};
100 $cur = $cur->{next}
101 4 ▶ while $cur->{next};
Branch: 1 branch
BranchTrueFalseTotal
$cur->{"next"} and do { $cur = $cur->{"next"} } 2 4 6
102 4 $cur->{next} = $i;
103 }
104 6 return $g;
105 7 };
106
107 0 ▶sub _add_color_group { goto &$add_color_group }
Subroutine _add_color_group: not called CC=1 SCAR=6.9
108 2 ▶$add_color_group = sub { # $g1 ($g1, $g2, |undef)
Subroutine __ANON__: called CC=7 SCAR=20.9
109 2 my ( $g1, $g2 ) = @_;
110 2 ▶ assert ( @_ >= 2 && @_ <= 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 and @_ <= 3 0 2 2
Condition33%1/3
@_ >= 2 and @_ <= 3
!ll&&!rl&&r
002
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2 @_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
ABresult
0X0
100
111
111 2 ▶ assert ( is_Object $g1 );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($g1) 0 2 2
112 2 ▶ assert ( is_Object $g2 and $g2->isa( TColorGroup ) );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($g2) and $g2->isa("TUI::ColorSel::ColorGroup") 0 2 2
Condition33%1/3
&is_Object($g2) and $g2->isa("TUI::ColorSel::ColorGroup")
!ll&&!rl&&r
002
MC/DC0%0/2
&is_Object($g2) and $g2->isa("TUI::ColorSel::ColorGroup")
&is_Object($g2) $g2->isa("TUI::ColorSel::ColorGroup")
Truth table33%1/3
A and B
A= &is_Object($g2)B= $g2->isa("TUI::ColorSel::ColorGroup")
ABresult
0X0
100
111
113 2 my $cur = $g1;
114 $cur = $cur->{next}
115 2 ▶ while $cur->{next};
Branch: 1 branch
BranchTrueFalseTotal
$cur->{"next"} and do { $cur = $cur->{"next"} } 1 2 3
116 2 $cur->{next} = $g2;
117 2 return $g1;
118 7 };
119
120 8 ▶sub add { # $g ($g1, $g2|$i, |$swap)
Subroutine add: called CC=3 SCAR=11.0
Pod documented
121 8 state $sig = signature(
122 pos => [
123 Object,
124 Object,
125 Bool, { optional => 1 }
126 ],
127 );
128 8 my ( $g1, $g2, $swap ) = $sig->( @_ );
129 8 ▶ assert ( not $swap ); # test if operands have been swapped
Branch: 1 branch
BranchTrueFalseTotal
if $swap 0 8 8
130 8 ▶ $g2->isa( TColorGroup )
Branch: 1 branch
BranchTrueFalseTotal
$g2->isa('TUI::ColorSel::ColorGroup') ? : 2 6 8
131 ? goto &$add_color_group
132 : goto &$add_color_item
133 }
134
135 use overload
136 7 ▶ '+' => \&add,
Subroutine BEGIN: called CC=1 SCAR=0.0
137 7 fallback => 1;
138
139 7 ▶my $mk_accessors = sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
140 7 my ( $pkg ) = @_;
141 7 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 7 7
142 7 ▶ assert ( defined $pkg );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg 0 7 7
143 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
144 7 my %HAS = %{"${pkg}::HAS"};
145 7 for my $field ( keys %HAS ) {
146 28 my $full_name = "${pkg}::$field";
147 14 ▶ *$full_name = sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
148 14 ▶ assert ( is_Object $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($_[0]) 0 14 14
149 14 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 14 14
150 0 $_[0]->{$field} = $_[1];
151 }
152 14 $_[0]->{$field};
153 28 };
154 }
155 7 };
156
157 7 __PACKAGE__->$mk_accessors();
158
159 7 1
160
161 __END__
« lib/TUI/Drivers/Event.pm ↑ Summary lib/TUI/Dialogs/MultiCheckBoxes.pm »