lib/TUI/Menus/MenuBox.pm

filter: Statementstmt 31.8% 50 / 157 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 54.1% 13 / 24 Podpod 71.4% 5 / 7 totaltotal 27.0% 68 / 251 CC 31 SCAR 41.2
CC
31
Cov
23%
__ANON__
182.0
draw
76.0
__ANON__
30.0
CRAP 61.8
« lib/TUI/StdDlg/FileDialog.pm ↑ Summary lib/TUI/StdDlg/FileList.pm »
1 package TUI::Menus::MenuBox;
2 # ABSTRACT: Pull-down or pop-up menu box
3
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 our $VERSION = '2.000002';
9 4 $VERSION =~ tr/_//d;
10 4 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @EXPORT = qw(
14 TMenuBox
15 new_TMenuBox
16 );
17
18 4 ▶use List::Util qw( max );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 Maybe
22 :is
23 :types
24 4 );
25
26 4 ▶use TUI::Menus::MenuView;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 sfShadow
30 ofPreProcess
31 4 );
32 4 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
33
34 sub TMenuBox() { __PACKAGE__ }
35 0 ▶sub name { 'TMenuBox' }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
36 0 ▶sub new_TMenuBox { __PACKAGE__->from(@_) }
Subroutine new_TMenuBox: not called CC=1 SCAR=6.9
Pod documented
37
38 4 extends TMenuView;
39
40 # declare global variables
41 4 our $frameChars =
42 # for UnitedStates code page
43 " \332\304\277 \300\304\331 \263 \263 \303\304\264 ";
44
45 # predeclare private methods
46 my (
47 4 $getRect,
48 $frameLine,
49 $drawLine,
50 );
51
52 0 ▶sub _getRect { goto &$getRect }
Subroutine _getRect: not called CC=1 SCAR=6.9
53 0 ▶$getRect = sub { # $rect ($bounds, $aMenu|undef)
Subroutine __ANON__: not called CC=13 SCAR=52.0
54 0 my ( $class, $bounds, $aMenu ) = @_;
55 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
56 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
57 0 ▶ assert ( is_Object $bounds );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($bounds) 0 0 0
58 0 ▶ assert ( !defined $aMenu or is_Object $aMenu );
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $aMenu or &is_Object($aMenu) 0 0 0
Condition0%0/3
not defined $aMenu or &is_Object($aMenu)
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $aMenu or &is_Object($aMenu)
not defined $aMenu &is_Object($aMenu)
Truth table0%0/3
not(A) or B
A= not defined $aMenuB= &is_Object($aMenu)
ABresult
1X1
011
000
59 0 my $w = 10;
60 0 my $h = 2;
61 0 ▶ if ( $aMenu ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aMenu) 0 0 0
62 0 ▶ for ( my $p = $aMenu->{items} ; $p ; $p = $p->{next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) 0 0 0
63 0 ▶ if ( $p->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"name"}) 0 0 0
64 0 my $l = length( $p->{name} ) + 6;
65 0 ▶ if ( !$p->{command} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $p->{'command'}) { } 0 0 0
elsif ($p->{'param'}) { } 0 0 0
66 0 $l += 3
67 }
68 elsif ( $p->{param} ) {
69 0 $l += length( $p->{param} ) + 2
70 }
71 0 $w = max( $l, $w );
72 }
73 0 $h++;
74 }
75 } #/ if ( $aMenu )
76
77 0 my $r = $bounds->clone();
78
79 0 ▶ if ( $r->{a}{x} + $w < $r->{b}{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'a'}{'x'} + $w < $r->{'b'}{'x'}) { } 0 0 0
80 0 $r->{b}{x} = $r->{a}{x} + $w;
81 }
82 else {
83 0 $r->{a}{x} = $r->{b}{x} - $w;
84 }
85
86 0 ▶ if ( $r->{a}{y} + $h < $r->{b}{y} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'a'}{'y'} + $h < $r->{'b'}{'y'}) { } 0 0 0
87 0 $r->{b}{y} = $r->{a}{y} + $h;
88 }
89 else {
90 0 $r->{a}{y} = $r->{b}{y} - $h;
91 }
92
93 0 return $r;
94 4 }; #/ sub $getRect
95
96 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
97 0 state $sig = signature(
98 method => 1,
99 named => [
100 bounds => Object,
101 menu => Maybe[Object], { alias => 'aMenu' },
102 parentMenu => Maybe[Object], { alias => 'aParentMenu' },
103 ],
104 caller_level => +1,
105 );
106 0 my ( $class, $args1 ) = $sig->( @_ );
107 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
108 my $args2 = $class->SUPER::BUILDARGS(
109 0 bounds => $class->$getRect( $args1->{bounds}, $args1->{menu} ),
110 );
111 0 return { %$args1, %$args2 };
112 }
113
114 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
115 0 my ( $self, $args ) = @_;
116 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
117 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
118 0 $self->{state} |= sfShadow;
119 0 $self->{options} |= ofPreProcess;
120 0 return;
121 }
122
123 0 ▶sub from { # $obj ($bounds, $aMenu|undef, $aParent|undef);
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
124 0 state $sig = signature(
125 method => 1,
126 pos => [Object, Maybe[Object], Maybe[Object]],
127 );
128 0 my ( $class, @args ) = $sig->( @_ );
129 0 return $class->new( bounds => $args[0], menu => $args[1],
130 parentMenu => $args[2]);
131 }
132
133 4 my ( $cNormal, $color );
134
135 0 ▶sub draw { # void ()
Subroutine draw: not called CC=9 SCAR=43.3
Pod documented
136 0 state $sig = signature(
137 method => Object,
138 pos => [],
139 );
140 0 my ( $self ) = $sig->( @_ );
141 0 my $b = TDrawBuffer->new();
142
143 0 $cNormal = $self->getColor( 0x0301 );
144 0 my $cSelect = $self->getColor( 0x0604 );
145 0 my $cNormDisabled = $self->getColor( 0x0202 );
146 0 my $cSelDisabled = $self->getColor( 0x0505 );
147 0 my $y = 0;
148 0 $color = $cNormal;
149 0 $self->$frameLine( $b, 0 );
150 0 $self->writeBuf( 0, $y++, $self->{size}{x}, 1, $b );
151
152 0 ▶ if ( $self->{menu} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"menu"}) 0 0 0
153 0 ▶ for ( my $p = $self->{menu}{items} ; $p ; $p = $p->{next} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) 0 0 0
154 0 $color = $cNormal;
155 0 ▶ if ( !$p->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $p->{'name'}) { } 0 0 0
156 0 $self->$frameLine( $b, 15 );
157 }
158 else {
159 {
160 0 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
161 0 ▶ if ( $p->{disabled} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p->{'disabled'}) { } 0 0 0
elsif ($p == $self->{'current'}) { } 0 0 0
162 $color = ( $p == $self->{current} )
163 0 ▶ ? $cSelDisabled
Branch: 1 branch
BranchTrueFalseTotal
$p == $self->{'current'} ? : 0 0 0
164 : $cNormDisabled;
165 }
166 elsif ( $p == $self->{current} ) {
167 0 $color = $cSelect;
168 }
169 }
170 0 $self->$frameLine( $b, 10 );
171 0 $b->moveCStr( 3, $p->{name}, $color );
172 0 ▶ if ( !$p->{command} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $p->{'command'}) { } 0 0 0
elsif ($p->{'param'}) { } 0 0 0
173 0 $b->putChar( $self->{size}{x} - 4, 16 );
174 }
175 elsif ( $p->{param} ) {
176 $b->moveStr( $self->{size}{x} - 3 - length( $p->{param} ),
177 0 $p->{param}, $color );
178 }
179 } #/ else [ if ( !$p->{name} ) ]
180 0 $self->writeBuf( 0, $y++, $self->{size}{x}, 1, $b );
181 } #/ for ( my $p = $self->{menu...})
182 } #/ if ( $self->{menu} )
183 0 $color = $cNormal;
184 0 $self->$frameLine( $b, 5 );
185 0 $self->writeBuf( 0, $y, $self->{size}{x}, 1, $b );
186 0 return;
187 } #/ sub draw
188
189 0 ▶sub getItemRect { # $rect ($item|undef)
Subroutine getItemRect: not called CC=2 SCAR=13.7
Pod documented
190 0 state $sig = signature(
191 method => Object,
192 pos => [Maybe[Object]],
193 );
194 0 my ( $self, $item ) = $sig->( @_ );
195 0 my $y = 1;
196 0 my $p = $self->{menu}{items};
197
198 {
199 0 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
200 0 ▶ while ( $p != $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p != $item) 0 0 0
201 0 $y++;
202 0 $p = $p->{next};
203 }
204 }
205 return TRect->new(
206 ax => 2,
207 ay => $y,
208 0 bx => $self->{size}{x} - 2,
209 by => $y + 1,
210 );
211 } #/ sub getItemRect
212
213 0 ▶$frameLine = sub { # void ($b, $n)
Subroutine __ANON__: not called CC=5 SCAR=34.0
214 0 my ( $self, $b, $n ) = @_;
215 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
216 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
217 0 ▶ assert ( is_ArrayLike $b );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ArrayLike($b) 0 0 0
218 0 ▶ assert ( is_Int $n );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($n) 0 0 0
219 0 $b->moveBuf(
220 0, [ unpack 'W*' => substr( $frameChars, $n, 2 ) ], $cNormal, 2 );
221 $b->moveChar(
222 0 2, substr( $frameChars, $n + 2, 1 ), $color, $self->{size}{x} - 4 );
223 0 $b->moveBuf( $self->{size}{x} - 2,
224 [ unpack 'W*' => substr( $frameChars, $n + 3, 2 ) ], $cNormal, 2 );
225 0 return;
226 4 };
227
228 0 ▶$drawLine = sub { # void ($b)
Subroutine __ANON__: not called CC=4 SCAR=28.3
229 0 my ( $self, $b ) = @_;
230 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
231 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
232 0 ▶ assert ( is_HashLike $b );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashLike($b) 0 0 0
233 ...
234 0 };
235
236 4 1
237
238 __END__
« lib/TUI/StdDlg/FileDialog.pm ↑ Summary lib/TUI/StdDlg/FileList.pm »