lib/TUI/Menus/MenuBox.pm

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