lib/TUI/Dialogs/InputLine.pm

filter: Statementstmt 20.3% 87 / 428 Branchbran 0.0% 0 / 194 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 41.3% 19 / 46 Podpod 77.7% 14 / 18 totaltotal 16.4% 120 / 730 CC 110 SCAR 61.6
CC
110
Cov
13%
handleEvent
1722.0
__ANON__
90.0
draw
42.0
CRAP 475.0
« lib/TUI/Dialogs/Cluster.pm ↑ Summary lib/TUI/Outline/OutlineViewer.pm »
1 package TUI::Dialogs::InputLine;
2 # ABSTRACT: Editable single-line text input control for dialogs.
3
4 34 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 34 our $VERSION = '2.000003';
9 34 $VERSION =~ tr/_//d;
10 34 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 34 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 34 our @EXPORT = qw(
14 TInputLine
15 new_TInputLine
16 );
17
18 34 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 34 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 Maybe
23 :is
24 :types
25 34 );
26
27 34 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 34 ▶use TUI::Dialogs::Const qw( cpInputLine );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 34 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 :evXXXX
31 kbShift
32 kbLeft
33 kbRight
34 kbHome
35 kbEnd
36 kbBack
37 kbDel
38 kbIns
39 meDoubleClick
40 34 );
41 34 ▶use TUI::Drivers::Util qw( ctrlToArrow );
Subroutine BEGIN: called CC=1 SCAR=0.0
42 34 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 34 ▶use TUI::Validate::Const qw( :TVTransfer );
Subroutine BEGIN: called CC=1 SCAR=0.0
44 34 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
45 cmCancel
46 cmValid
47 ofSelectable
48 ofFirstClick
49 :sfXXXX
50 34 );
51 34 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 34 ▶use TUI::Views::Palette;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 34 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
54
55 sub TInputLine() { __PACKAGE__ }
56 sub name() { 'TInputLine' }
57 0 ▶sub new_TInputLine { __PACKAGE__->from(@_) }
Subroutine new_TInputLine: not called CC=1 SCAR=6.9
Pod documented
58
59 34 extends TView;
60
61 34 ▶use constant CONTROL_Y => 25;
Subroutine BEGIN: called CC=1 SCAR=0.0
62
63 # declare global variables
64 34 our $rightArrow = "\x10";
65 34 our $leftArrow = "\x11";
66
67 # public attributes
68 34 has data => ( is => 'rw', default => '' );
69 0 ▶has maxLen => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
70 34 has curPos => ( is => 'rw', default => 0 );
71 34 has firstPos => ( is => 'rw', default => 0 );
72 34 has selStart => ( is => 'ro', default => 0 );
73 34 has selEnd => ( is => 'ro', default => 0 );
74
75 # private attributes
76 34 has validator => ( is => 'bare' );
77 34 has anchor => ( is => 'bare', default => -1 );
78 34 has oldAnchor => ( is => 'bare', default => -1 ); # New to save state info
79 34 has oldData => ( is => 'bare', default => '' );
80 34 has oldCurPos => ( is => 'bare' );
81 34 has oldFirstPos => ( is => 'bare' );
82 34 has oldSelStart => ( is => 'bare' );
83 34 has oldSelEnd => ( is => 'bare' );
84
85 # predeclare private methods
86 my (
87 34 $canScroll,
88 $mouseDelta,
89 $mousePos,
90 $deleteSelect,
91 $adjustSelectBlock,
92 $saveState,
93 $restoreState,
94 $checkValid,
95 );
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 maxLen => Int, { alias => 'aMaxLen' },
103 validator => Object, { alias => 'aValid', optional => 1 },
104 ],
105 caller_level => +1,
106 );
107 0 my ( $class, $args ) = $sig->( @_ );
108 0 return { %$args };
109 }
110
111 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
112 0 my ( $self, $args ) = @_;
113 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
114 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
115 0 $self->{state} |= sfCursorVis;
116 0 $self->{options} |= ofSelectable | ofFirstClick;
117 0 return;
118 }
119
120 0 ▶sub from { # $obj ($bounds, $aMaxLen, |$aValid)
Subroutine from: not called CC=4 SCAR=30.0
Pod undocumented
121 0 state $sig = signature(
122 method => 1,
123 pos => [
124 Object,
125 Int,
126 Object, { optional => 1 }
127 ],
128 );
129 0 my ( $class, @args ) = $sig->( @_ );
130 0 SWITCH: for ( scalar @args ) {
131 0 ▶ $_ == 2 and return $class->new( bounds => $args[0], maxLen => $args[1] );
Branch: 1 branch
BranchTrueFalseTotal
$_ == 2 and return $class->new("bounds", $args[0], "maxLen", $args[1]) 0 0 0
132 0 ▶ $_ == 3 and return $class->new( bounds => $args[0], maxLen => $args[1],
Branch: 1 branch
BranchTrueFalseTotal
$_ == 3 and return $class->new("bounds", $args[0], "maxLen", $args[1], "validator", $args[2]) 0 0 0
133 validator => $args[2] );
134 }
135 }
136
137 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=3 SCAR=24.8
Pod documented
138 0 my ( $self, $in_global_destruction ) = @_;
139 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
140 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
141 0 $self->{data} = undef;
142 0 $self->{oldData} = undef;
143 0 $self->destroy( $self->{validator} );
144 0 return;
145 }
146
147 0 ▶sub dataSize { # $dSize ()
Subroutine dataSize: not called CC=3 SCAR=24.8
Pod documented
148 0 state $sig = signature(
149 method => Object,
150 pos => [],
151 );
152 0 my ( $self ) = $sig->( @_ );
153 0 my $dSize = 0;
154
155 0 ▶ if ( $self->{validator} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"validator"}) 0 0 0
156 0 $dSize = $self->{validator}->transfer( $self->{data}, undef, vtDataSize );
157 }
158 0 ▶ if ( $dSize == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dSize == 0) 0 0 0
159 0 $dSize = 1; # In Perl, this must be the number of entries in the list
160 }
161 0 return $dSize;
162 } #/ sub dataSize
163
164 0 ▶sub draw { # void ()
Subroutine draw: not called CC=6 SCAR=37.4
Pod documented
165 0 state $sig = signature(
166 method => Object,
167 pos => [],
168 );
169 0 my ( $self ) = $sig->( @_ );
170
171 0 my ( $l, $r );
172 0 my $b = TDrawBuffer->new();
173 0 ▶ my $color = $self->{state} & sfFocused
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} & 64 ? : 0 0 0
174 ? $self->getColor( 2 )
175 : $self->getColor( 1 );
176
177 0 $b->moveChar( 0, ' ', $color, $self->{size}{x} );
178 0 my $buf = substr( $self->{data}, $self->{firstPos}, $self->{size}{x} - 2 );
179 0 $b->moveStr( 1, $buf, $color );
180
181 0 ▶ if ( $self->$canScroll( 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$canScroll(1)) 0 0 0
182 0 $b->moveChar( $self->{size}{x} - 1, $rightArrow, $self->getColor( 4 ), 1 );
183 }
184 0 ▶ if ( $self->{state} & sfSelected ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} & 32) 0 0 0
185 0 ▶ if ( $self->$canScroll( -1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$canScroll(-1)) 0 0 0
186 0 $b->moveChar( 0, $leftArrow, $self->getColor( 4 ), 1 );
187 }
188 0 $l = $self->{selStart} - $self->{firstPos};
189 0 $r = $self->{selEnd} - $self->{firstPos};
190 0 $l = max( 0, $l );
191 0 $r = min( $self->{size}{x} - 2, $r );
192 0 ▶ if ( $l < $r ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < $r) 0 0 0
193 0 $b->moveChar( $l + 1, undef, $self->getColor( 3 ), $r - $l );
194 }
195 } #/ if ( ( $self->{state} ...))
196 0 $self->writeLine( 0, 0, $self->{size}{x}, $self->{size}{y}, $b );
197 0 $self->setCursor( $self->{curPos} - $self->{firstPos} + 1, 0 );
198 0 return;
199 } #/ sub draw
200
201 0 ▶sub getData { # void (\@rec)
Subroutine getData: not called CC=4 SCAR=30.0
Pod documented
202 0 state $sig = signature(
203 method => Object,
204 pos => [ArrayLike],
205 );
206 0 my ( $self, $rec ) = $sig->( @_ );
207 0 ▶ if ( !$self->{validator}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 2)) 0 0 0
Condition0%0/3
$self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 2)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 2)
$self->{"validator"} $self->{"validator"}->transfer($self->{"data"}, $rec, 2)
Truth table0%0/3
A and B
A= $self->{"validator"}B= $self->{"validator"}->transfer($self->{"data"}, $rec, 2)
ABresult
0X0
100
111
208 || !$self->{validator}->transfer( $self->{data}, $rec, vtGetData )
209 0 ) {
210 0 ▶ assert ( $self->dataSize() );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dataSize 0 0 0
211 0 $rec->[0] = $self->{data};
212 }
213 0 return;
214 } #/ sub getData
215
216 0 ▶sub getPalette { # $palette ()
Subroutine getPalette: not called CC=1 SCAR=6.9
Pod documented
217 0 state $sig = signature(
218 method => Object,
219 pos => [],
220 );
221 0 my ( $self ) = $sig->( @_ );
222 0 state $palette = TPalette->new(
223 data => cpInputLine,
224 size => length( cpInputLine ),
225 );
226 0 return $palette->clone();
227 }
228
229 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=41 SCAR=74.5
Pod documented
230 0 state $sig = signature(
231 method => Object,
232 pos => [Object],
233 );
234 0 my ( $self, $event ) = $sig->( @_ );
235 # Home, Left Arrow, Right Arrow, End, Ctrl-Left Arrow, Ctrl-Right Arrow
236 0 my @padKeys = ( 0x47, 0x4b, 0x4d, 0x4f, 0x73, 0x74 );
237 0 $self->SUPER::handleEvent( $event );
238
239 0 my ( $delta, $i );
240 0 ▶ return unless ( $self->{state} & sfSelected );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"state"} & 32 0 0 0
241 0 SWITCH: for ( $event->{what} ) {
242 0 ▶ evMouseDown == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1 == $_ and do { if ($self->$canScroll($delta = $self->$mouseDelta($event))) { do { if ($self->$canScroll($delta)) { $self->{"firstPos"} += $delta; $self->drawView; } } while $self->mouseEvent($event, 8); } elsif ($event->{"mouse"}{"eventFlags"} & 2) { $self->selectAll(1); } else { $self->{"anchor"} = $self->$mousePos($event); do { if ($event->{"what"} == 8) { $delta = $self->$mouseDelta($event); if ($self->$canScroll($delta)) { $self->{"firstPos"} += $delta; } ; } ; $self->{"curPos"} = $self->$mousePos($event); $self->$adjustSelectBlock; $self->drawView } while $self->mouseEvent($event, 12); } ; $self->clearEvent($event); last } 0 0 0
243 0 ▶ if ( $self->$canScroll( $delta = $self->$mouseDelta( $event ) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->$canScroll($delta = $self->$mouseDelta($event))) { } 0 0 0
elsif ($event->{'mouse'}{'eventFlags'} & 2) { } 0 0 0
244 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->mouseEvent($event, 8) and do { do { if ($self->$canScroll($delta)) { $self->{"firstPos"} += $delta; $self->drawView; } } } 0 0 0
245 0 ▶ if ( $self->$canScroll( $delta ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$canScroll($delta)) 0 0 0
246 0 $self->{firstPos} += $delta;
247 0 $self->drawView();
248 }
249 } while $self->mouseEvent( $event, evMouseAuto );
250 } #/ if ( $self->$canScroll(...))
251 elsif ( $event->{mouse}{eventFlags} & meDoubleClick ) {
252 0 $self->selectAll( 1 );
253 }
254 else {
255 0 $self->{anchor} = $self->$mousePos( $event );
256 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->mouseEvent($event, 12) and do { do { if ($event->{"what"} == 8) { $delta = $self->$mouseDelta($event); if ($self->$canScroll($delta)) { $self->{"firstPos"} += $delta; } ; } ; $self->{"curPos"} = $self->$mousePos($event); $self->$adjustSelectBlock; $self->drawView } } 0 0 0
257 0 ▶ if ( $event->{what} == evMouseAuto ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 8) 0 0 0
258 0 $delta = $self->$mouseDelta( $event );
259 0 ▶ if ( $self->$canScroll( $delta ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$canScroll($delta)) 0 0 0
260 0 $self->{firstPos} += $delta;
261 }
262 }
263 0 $self->{curPos} = $self->$mousePos( $event );
264 0 $self->$adjustSelectBlock();
265 0 $self->drawView();
266 } while $self->mouseEvent( $event, evMouseMove | evMouseAuto );
267 } #/ else [ if ( $self->$canScroll(...))]
268 0 $self->clearEvent( $event );
269 0 last;
270 };
271
272 0 ▶ evKeyDown == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
16 == $_ and 0 0 0
273 0 $self->$saveState();
274 $event->{keyDown}{keyCode} =
275 0 ctrlToArrow( $event->{keyDown}{keyCode} );
276 0 my $scanCode = $event->{keyDown}{charScan}{scanCode};
277 0 my $isPad = grep { $_ == $scanCode } @padKeys;
278 0 my $hasShift = $event->{keyDown}{controlKeyState} & kbShift;
279 0 ▶ if ( $isPad && $hasShift ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isPad and $hasShift) { } 0 0 0
Condition0%0/3
$isPad and $hasShift
!ll&&!rl&&r
000
MC/DC0%0/2
$isPad and $hasShift
$isPad $hasShift
Truth table0%0/3
A and B
A= $isPadB= $hasShift
ABresult
0X0
100
111
280 0 $event->{keyDown}{charScan}{charCode} = 0;
281 0 ▶ if ( $self->{anchor} < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"anchor"} < 0) 0 0 0
282 0 $self->{anchor} = $self->{curPos};
283 }
284 }
285 else {
286 0 $self->{anchor} = -1;
287 }
288 0 SWITCH: for ( $event->{keyDown}{keyCode} ) {
289 0 ▶ kbLeft == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
19200 == $_ and do { if ($self->{"curPos"} > 0) { --$self->{"curPos"}; } ; last } 0 0 0
290 0 ▶ if ( $self->{curPos} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} > 0) 0 0 0
291 0 $self->{curPos}--;
292 }
293 0 last;
294 };
295 0 ▶ kbRight == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
19712 == $_ and do { if ($self->{"curPos"} < length $self->{"data"}) { ++$self->{"curPos"}; } ; last } 0 0 0
296 0 ▶ if ( $self->{curPos} < length( $self->{data} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} < length $self->{"data"}) 0 0 0
297 0 $self->{curPos}++;
298 }
299 0 last;
300 };
301 0 ▶ kbHome == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
18176 == $_ and do { $self->{"curPos"} = 0; last } 0 0 0
302 0 $self->{curPos} = 0;
303 0 last;
304 };
305 0 ▶ kbEnd == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
20224 == $_ and do { $self->{"curPos"} = length $self->{"data"}; last } 0 0 0
306 0 $self->{curPos} = length( $self->{data} );
307 0 last;
308 };
309 0 ▶ kbBack == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
3592 == $_ and 0 0 0
310 0 ▶ if ( $self->{curPos} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} > 0) 0 0 0
311 0 substr( $self->{data}, $self->{curPos} - 1, 1, '' );
312 0 $self->{curPos}--;
313 0 ▶ if ( $self->{firstPos} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"firstPos"} > 0) 0 0 0
314 0 $self->{firstPos}--;
315 }
316 0 $self->$checkValid( true );
317 } #/ if ( $self->{curPos} >...)
318 0 last;
319 };
320 0 ▶ kbDel == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
21248 == $_ and 0 0 0
321 0 ▶ if ( $self->{selStart} == $self->{selEnd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"selStart"} == $self->{"selEnd"}) 0 0 0
322 0 ▶ if ( $self->{curPos} < length( $self->{data} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} < length $self->{"data"}) 0 0 0
323 0 $self->{selStart} = $self->{curPos};
324 0 $self->{selEnd} = $self->{curPos} + 1;
325 }
326 }
327 0 $self->$deleteSelect();
328 0 $self->$checkValid( true );
329 0 last;
330 };
331 0 ▶ kbIns == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
20992 == $_ and do { $self->setState(4, !($self->{"state"} & 4)); last } 0 0 0
332 0 $self->setState( sfCursorIns, !( $self->{state} & sfCursorIns ) );
333 0 last;
334 };
335 DEFAULT: {
336 0 my $ch = $event->{keyDown}{charScan}{charCode};
337 0 ▶ if ( defined $ch && $ch >= ord( ' ' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ch and $ch >= 32) { } 0 0 0
elsif (defined $ch and $ch == 25) { } 0 0 0
Condition0%0/3
defined $ch and $ch >= 32
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ch and $ch >= 32
defined $ch $ch >= 32
Truth table0%0/3
A and B
A= defined $chB= $ch >= 32
ABresult
0X0
100
111
338 0 $self->$deleteSelect();
339 0 ▶ if ( $self->{state} & sfCursorIns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} & 4) 0 0 0
340 # The following is always a signed comparison in Perl!
341 0 ▶ if ( $self->{curPos} < length( $self->{data} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} < length $self->{"data"}) 0 0 0
342 0 substr( $self->{data}, $self->{curPos}, 1, '' );
343 }
344 }
345 0 ▶ if ( $self->$checkValid( true ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if () 0 0 0
346 0 my $strlen = length( $self->{data} );
347 0 ▶ if ( $strlen < $self->{maxLen} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strlen < $self->{"maxLen"}) 0 0 0
348 0 ▶ if ( $self->{firstPos} > $self->{curPos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"firstPos"} > $self->{"curPos"}) 0 0 0
349 0 $self->{firstPos} = $self->{curPos};
350 }
351 # In Perl, only move the data if the insertion is not at end
352 0 ▶ if ( $self->{curPos} < $strlen ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} < $strlen) 0 0 0
353 substr( $self->{data}, $self->{curPos} + 1 ) =
354 substr( $self->{data}, $self->{curPos} )
355 0 }
356 0 substr( $self->{data}, $self->{curPos}, 1 ) = chr( $ch );
357 0 $self->{curPos}++;
358 }
359 0 $self->$checkValid( false );
360 } #/ if ( $self->$checkValid...)
361 } #/ if ( defined $ch && $ch...)
362 ▶ elsif ( defined $ch && $ch == CONTROL_Y ) {
Condition0%0/3
defined $ch and $ch == 25
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ch and $ch == 25
defined $ch $ch == 25
Truth table0%0/3
A and B
A= defined $chB= $ch == 25
ABresult
0X0
100
111
363 0 $self->{data} = EOS;
364 0 $self->{curPos} = 0;
365 }
366 else {
367 0 return;
368 }
369 0 last;
370 };
371 } #/ SWITCH: for ( $event->{keyDown}...)
372
373 0 $self->$adjustSelectBlock();
374 0 ▶ if ( $self->{firstPos} > $self->{curPos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"firstPos"} > $self->{"curPos"}) 0 0 0
375 0 $self->{firstPos} = $self->{curPos};
376 }
377 0 $i = $self->{curPos} - $self->{size}{x} + 2;
378 0 ▶ if ( $self->{firstPos} < $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"firstPos"} < $i) 0 0 0
379 0 $self->{firstPos} = $i;
380 }
381 0 $self->drawView();
382 0 $self->clearEvent( $event );
383 0 last;
384 };
385 } #/ SWITCH: for ( $event->{what} )
386 0 return;
387 } #/ sub handleEvent
388
389 0 ▶sub selectAll { # void ($enable)
Subroutine selectAll: not called CC=2 SCAR=17.9
Pod documented
390 0 state $sig = signature(
391 method => Object,
392 pos => [Bool],
393 );
394 0 my ( $self, $enable ) = $sig->( @_ );
395 0 $self->{selStart} = 0;
396 0 ▶ if ( $enable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable) { } 0 0 0
397 0 my $len = length( $self->{data} );
398 0 $self->{curPos} = $self->{selEnd} = $len;
399 }
400 else {
401 0 $self->{curPos} = $self->{selEnd} = 0;
402 }
403 0 $self->{firstPos} = max( 0, $self->{curPos} - $self->{size}{x} + 2 );
404 0 $self->{anchor} = 0; # This sets anchor to avoid deselect on init selection
405 0 $self->drawView();
406 0 return;
407 } #/ sub selectAll
408
409 0 ▶sub setData { # void (\@rec)
Subroutine setData: not called CC=6 SCAR=37.4
Pod documented
410 0 state $sig = signature(
411 method => Object,
412 pos => [ArrayLike],
413 );
414 0 my ( $self, $rec ) = $sig->( @_ );
415 0 ▶ if ( !$self->{validator}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 1)) 0 0 0
Condition0%0/3
$self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"validator"} and $self->{"validator"}->transfer($self->{"data"}, $rec, 1)
$self->{"validator"} $self->{"validator"}->transfer($self->{"data"}, $rec, 1)
Truth table0%0/3
A and B
A= $self->{"validator"}B= $self->{"validator"}->transfer($self->{"data"}, $rec, 1)
ABresult
0X0
100
111
416 || !$self->{validator}->transfer( $self->{data}, $rec, vtSetData )
417 0 ) {
418 0 ▶ assert ( $self->dataSize() );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dataSize 0 0 0
419 0 ▶ assert ( defined $rec->[0] and !ref $rec->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec->[0] and not ref $rec->[0] 0 0 0
Condition0%0/3
defined $rec->[0] and not ref $rec->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rec->[0] and not ref $rec->[0]
defined $rec->[0] not ref $rec->[0]
Truth table0%0/3
A and not(B)
A= defined $rec->[0]B= not ref $rec->[0]
ABresult
0X0
100
111
420 0 $self->{data} = substr( $rec->[0], 0, $self->{maxLen} );
421 } #/ if ( !$self->{validator...})
422 0 $self->selectAll( true );
423 0 return;
424 } #/ sub setData
425
426 0 ▶sub setState { # void ($aState, $enable)
Subroutine setState: not called CC=4 SCAR=30.0
Pod documented
427 0 state $sig = signature(
428 method => Object,
429 pos => [PositiveOrZeroInt, Bool],
430 );
431 0 my ( $self, $aState, $enable ) = $sig->( @_ );
432 0 $self->SUPER::setState( $aState, $enable );
433 0 ▶ if ( $aState == sfSelected
Branch: 1 branch
BranchTrueFalseTotal
if ($aState == 32 or $aState == 16 and $self->{"state"} & 32) 0 0 0
Condition0%0/6
$aState == 32 or $aState == 16 and $self->{"state"} & 32
l!l&&r!l&&!r
000
$aState == 16 and $self->{"state"} & 32
!ll&&!rl&&r
000
MC/DC0%0/3
$aState == 32 or $aState == 16 and $self->{"state"} & 32
$aState == 32 $aState == 16 $self->{"state"} & 32
Truth table0%0/4
A or B and C
A= $aState == 32B= $aState == 16C= $self->{"state"} & 32
ABCresult
1XX1
0111
00X0
0100
434 || ( $aState == sfActive && ( $self->{state} & sfSelected ) )
435 ) {
436 0 $self->selectAll( $enable );
437 }
438 0 return;
439 } #/ sub setState
440
441 0 ▶sub valid { # $bool ($command)
Subroutine valid: not called CC=6 SCAR=37.4
Pod documented
442 0 state $sig = signature(
443 method => Object,
444 pos => [PositiveOrZeroInt],
445 );
446 0 my ( $self, $command ) = $sig->( @_ );
447
448 0 ▶ if ( $self->{validator} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"validator"}) 0 0 0
449 0 ▶ if ( $command == cmValid ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($command == 0) { } 0 0 0
elsif ($command != 11) { } 0 0 0
450 my $status = $self->{validator}->can( 'status' )
451 ? $self->{validator}->status()
452 0 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'validator'}->can('status') ? : 0 0 0
453 0 return $status == 0;
454 }
455 elsif ( $command != cmCancel ) {
456 0 ▶ unless ( $self->{validator}->validate( $self->{data} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"validator"}->validate($self->{"data"})) 0 0 0
457 0 $self->select();
458 0 return false;
459 }
460 }
461 }
462 0 return true;
463 }
464
465 0 ▶sub setValidator { # void ($aValid|undef)
Subroutine setValidator: not called CC=2 SCAR=17.9
Pod documented
466 0 state $sig = signature(
467 method => Object,
468 pos => [Maybe[Object]],
469 );
470 0 my ( $self, $aValid ) = $sig->( @_ );
471 0 ▶ if ( $self->{validator} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"validator"}) 0 0 0
472 0 $self->destroy( $self->{validator} );
473 }
474 0 $self->{validator} = $aValid;
475 0 return;
476 } #/ sub setValidator
477
478 0 ▶$canScroll = sub { # bool ($delta)
Subroutine __ANON__: not called CC=6 SCAR=37.4
479 0 my ( $self, $delta ) = @_;
480 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
481 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
482 0 ▶ assert ( is_Int $delta );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($delta) 0 0 0
483 0 ▶ if ( $delta < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($delta < 0) { } 0 0 0
elsif ($delta > 0) { } 0 0 0
484 0 return $self->{firstPos} > 0;
485 }
486 elsif ( $delta > 0 ) {
487 0 return length( $self->{data} ) - $self->{firstPos} + 2 > $self->{size}{x};
488 }
489 else {
490 0 return false;
491 }
492 34 };
493
494 0 ▶$mouseDelta = sub { # void ($event)
Subroutine __ANON__: not called CC=6 SCAR=37.4
495 0 my ( $self, $event ) = @_;
496 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
497 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
498 0 ▶ assert ( is_Object $event );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($event) 0 0 0
499 0 my $mouse = $self->makeLocal( $event->{mouse}{where} );
500
501 0 ▶ if ( $mouse->{x} <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mouse->{'x'} <= 0) { } 0 0 0
502 0 return -1;
503 }
504 else {
505 0 ▶ $mouse->{x} >= $self->{size}{x} - 1 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mouse->{'x'} >= $self->{'size'}{'x'} - 1 ? : 0 0 0
506 }
507 34 };
508
509 0 ▶$mousePos = sub { # void ($event)
Subroutine __ANON__: not called CC=4 SCAR=30.0
510 0 my ( $self, $event ) = @_;
511 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
512 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
513 0 ▶ assert ( is_Object $event );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($event) 0 0 0
514 0 my $mouse = $self->makeLocal( $event->{mouse}{where} );
515 0 $mouse->{x} = max( $mouse->{x}, 1 );
516 0 my $pos = $mouse->{x} + $self->{firstPos} - 1;
517 0 $pos = max( $pos, 0 );
518 0 $pos = min( $pos, length( $self->{data} ) );
519 0 return $pos;
520 34 };
521
522 0 ▶$deleteSelect = sub { # void ()
Subroutine __ANON__: not called CC=4 SCAR=30.0
523 0 my ( $self ) = @_;
524 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
525 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
526 0 ▶ if ( $self->{selStart} < $self->{selEnd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"selStart"} < $self->{"selEnd"}) 0 0 0
527 substr( $self->{data}, $self->{selStart} ) =
528 0 substr( $self->{data}, $self->{selEnd} );
529 0 $self->{curPos} = $self->{selStart};
530 } #/ if ( $self->{selStart}...)
531 0 return;
532 34 };
533
534 0 ▶$adjustSelectBlock = sub { # void ()
Subroutine __ANON__: not called CC=5 SCAR=34.0
535 0 my ( $self ) = @_;
536 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
537 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
538 0 ▶ if ( $self->{anchor} < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'anchor'} < 0) { } 0 0 0
elsif ($self->{'anchor'} > $self->{'curPos'}) { } 0 0 0
539 0 $self->{selStart} = 0;
540 0 $self->{selEnd} = 0;
541 }
542 elsif ( $self->{anchor} > $self->{curPos} ) {
543 0 $self->{selStart} = $self->{curPos};
544 0 $self->{selEnd} = $self->{anchor};
545 }
546 else {
547 0 $self->{selStart} = $self->{anchor};
548 0 $self->{selEnd} = $self->{curPos};
549 }
550 0 return;
551 34 };
552
553 0 ▶$saveState = sub { # void ()
Subroutine __ANON__: not called CC=4 SCAR=30.0
554 0 my ( $self ) = @_;
555 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
556 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
557 0 ▶ if ( $self->{validator} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"validator"}) 0 0 0
558 0 $self->{oldData} = $self->{data};
559 0 $self->{oldCurPos} = $self->{curPos};
560 0 $self->{oldFirstPos} = $self->{firstPos};
561 0 $self->{oldSelStart} = $self->{selStart};
562 0 $self->{oldSelEnd} = $self->{selEnd};
563 0 $self->{oldAnchor} = $self->{anchor};
564 } #/ if ( $self->{validator...})
565 0 return;
566 34 };
567
568 0 ▶$restoreState = sub { # void ()
Subroutine __ANON__: not called CC=4 SCAR=30.0
569 0 my ( $self ) = @_;
570 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
571 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
572 0 ▶ if ( $self->{validator} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"validator"}) 0 0 0
573 0 $self->{data} = $self->{oldData};
574 0 $self->{curPos} = $self->{oldCurPos};
575 0 $self->{firstPos} = $self->{oldFirstPos};
576 0 $self->{selStart} = $self->{oldSelStart};
577 0 $self->{selEnd} = $self->{oldSelEnd};
578 0 $self->{anchor} = $self->{oldAnchor};
579 } #/ if ( $self->{validator...})
580 0 return;
581 34 };
582
583 0 ▶$checkValid = sub { # $bool ($noAutoFill)
Subroutine __ANON__: not called CC=9 SCAR=45.0
584 0 my ( $self, $noAutoFill ) = @_;
585 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
586 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
587 0 ▶ assert ( is_Bool $noAutoFill );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Bool($noAutoFill) 0 0 0
588 0 ▶ return true unless $self->{validator};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"validator"} 0 0 0
589 0 my $oldLen = length( $self->{data} );
590 0 my $newData = $self->{data};
591 0 ▶ if ( !$self->{validator}->isValidInput( $newData, $noAutoFill ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'validator'}->isValidInput($newData, $noAutoFill)) { } 0 0 0
592 0 $self->$restoreState();
593 0 return false;
594 }
595 else {
596 0 ▶ if ( length( $newData ) > $self->{maxLen} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $newData > $self->{"maxLen"}) 0 0 0
597 0 substr( $newData, $self->{maxLen} ) = '';
598 }
599 0 $self->{data} = $newData;
600 0 ▶ if ( $self->{curPos} >= $oldLen && length( $self->{data} ) > $oldLen ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"curPos"} >= $oldLen and length $self->{"data"} > $oldLen) 0 0 0
Condition0%0/3
$self->{"curPos"} >= $oldLen and length $self->{"data"} > $oldLen
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"curPos"} >= $oldLen and length $self->{"data"} > $oldLen
$self->{"curPos"} >= $oldLen length $self->{"data"} > $oldLen
Truth table0%0/3
A and B
A= $self->{"curPos"} >= $oldLenB= length $self->{"data"} > $oldLen
ABresult
0X0
100
111
601 0 $self->{curPos} = length( $self->{data} );
602 }
603 0 return true;
604 } #/ else [ if ( !$self->{validator...})]
605 34 };
606
607 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
608 0 state $sig = signature(
609 method => Object,
610 pos => [Object],
611 );
612 0 my ( $self, $os ) = $sig->( @_ );
613 0 $self->SUPER::write( $os );
614 $os->put(
615 $self->{maxLen},
616 $self->{curPos},
617 $self->{firstPos},
618 $self->{selStart},
619 $self->{selEnd},
620 $self->{data},
621 $self->{validator},
622 0 );
623 0 return;
624 }
625
626 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
627 0 state $sig = signature(
628 method => Object,
629 pos => [Object],
630 );
631 0 my ( $self, $is ) = $sig->( @_ );
632 0 $self->SUPER::read( $is );
633 0 $self->{maxLen} = $is->get();
634 0 $self->{curPos} = $is->get();
635 0 $self->{firstPos} = $is->get();
636 0 $self->{selStart} = $is->get();
637 0 $self->{selEnd} = $is->get();
638 0 $self->{data} = $is->get();
639 0 $self->{oldData} = '';
640 0 $self->{state} |= sfCursorVis;
641 0 $self->{validator} = $is->get();
642 # $self->{options} |= ofSelectable | ofFirstClick;
643 0 return $self;
644 }
645
646 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
647 0 my ( $class ) = @_;
648 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
649 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
650 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
651 0 return $class->new(
652 bounds => TRect->new(),
653 maxLen => 0,
654 );
655 }
656
657 34 1
658
659 __END__
« lib/TUI/Dialogs/Cluster.pm ↑ Summary lib/TUI/Outline/OutlineViewer.pm »