lib/TUI/Dialogs/Label.pm

filter: Statementstmt 51.5% 68 / 132 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 64.2% 18 / 28 Podpod 87.5% 7 / 8 totaltotal 41.3% 93 / 225 CC 21 SCAR 34.9
CC
21
Cov
38%
handleEvent
106.8
__ANON__
42.0
draw
20.0
CRAP 32.7
« lib/TUI/StdDlg/FileInputLine.pm ↑ Summary lib/TUI/StdDlg/Dir.pm »
1 package TUI::Dialogs::Label;
2 # ABSTRACT: Provides a descriptive label linked to another dialog control.
3
4 26 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 26 our $VERSION = '2.000002';
9 26 $VERSION =~ tr/_//d;
10 26 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 26 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 26 our @EXPORT = qw(
14 TLabel
15 new_TLabel
16 );
17
18 26 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 26 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 Maybe
21 is_Object
22 :types
23 26 );
24
25 26 ▶use TUI::Dialogs::Const qw( cpLabel );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 26 ▶use TUI::Dialogs::StaticText;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 26 ▶use TUI::Dialogs::Util qw( hotKey );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 26 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 :evXXXX
30 26 );
31 26 ▶use TUI::Drivers::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
32 cstrlen
33 getAltCode
34 26 );
35 26 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
36 cmReceivedFocus
37 cmReleasedFocus
38 :ofXXXX
39 phPostProcess
40 sfFocused
41 26 );
42 26 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 26 ▶use TUI::Views::Palette;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 26 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
45
46 sub TLabel() { __PACKAGE__ }
47 sub name() { 'TLabel' }
48 0 ▶sub new_TLabel { __PACKAGE__->from(@_) }
Subroutine new_TLabel: not called CC=1 SCAR=6.9
Pod documented
49
50 26 extends TStaticText;
51
52 # import global variables
53 26 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
54 $showMarkers
55 $specialChars
56 26 );
57 {
58 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 26 *showMarkers = \${ TView . '::showMarkers' };
60 26 *specialChars = \${ TView . '::specialChars' };
61 }
62
63 # protected attributes
64 0 ▶has link => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
65 26 has light => ( is => 'ro', default => false );
66
67 # predeclare private methods
68 my (
69 26 $focusLink,
70 );
71
72 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
73 0 state $sig = signature(
74 method => 1,
75 named => [
76 bounds => Object,
77 text => Str, { alias => 'aText' },
78 link => Maybe[Object], { alias => 'aLink' },
79 ],
80 caller_level => +1,
81 );
82 0 my ( $class, $args ) = $sig->( @_ );
83 0 return { %$args };
84 }
85
86 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
87 0 my ( $self, $args ) = @_;
88 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
89 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
90 0 $self->{options} |= ofPreProcess | ofPostProcess;
91 0 $self->{eventMask} |= evBroadcast;
92 0 return;
93 }
94
95 0 ▶sub from { # $obj ($bounds, $aText, $aLink|undef)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
96 0 state $sig = signature(
97 method => 1,
98 pos => [Object, Str, Maybe[Object]],
99 );
100 0 my ( $class, @args ) = $sig->( @_ );
101 0 return $class->new( bounds => $args[0], text => $args[1], link => $args[2] );
102 }
103
104 0 ▶sub shutDown { # void ()
Subroutine shutDown: not called CC=1 SCAR=6.9
Pod documented
105 0 state $sig = signature(
106 method => Object,
107 pos => [],
108 );
109 0 my ( $self ) = $sig->( @_ );
110 0 $self->{link} = undef;
111 0 $self->SUPER::shutDown();
112 0 return;
113 }
114
115 0 ▶sub draw { # void ()
Subroutine draw: not called CC=4 SCAR=30.0
Pod documented
116 0 state $sig = signature(
117 method => Object,
118 pos => [],
119 );
120 0 my ( $self ) = $sig->( @_ );
121 0 my $color;
122 0 my $b = TDrawBuffer->new();
123 0 my $scOff;
124
125 0 ▶ if ( $self->{light} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'light'}) { } 0 0 0
126 0 $color = $self->getColor( 0x0402 );
127 0 $scOff = 0;
128 }
129 else {
130 0 $color = $self->getColor( 0x0301 );
131 0 $scOff = 4;
132 }
133
134 0 $b->moveChar( 0, ' ', $color, $self->{size}{x} );
135 0 ▶ if ( $self->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"text"}) 0 0 0
136 0 $b->moveCStr( 1, $self->{text}, $color );
137 }
138 0 ▶ if ( $showMarkers ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TUI::Dialogs::Label::showMarkers) 0 0 0
139 0 $b->putChar( 0, $specialChars->[$scOff] );
140 }
141 0 $self->writeLine( 0, 0, $self->{size}{x}, 1, $b );
142 0 return;
143 }
144
145 0 ▶sub getPalette { # $palette ()
Subroutine getPalette: not called CC=1 SCAR=6.9
Pod documented
146 0 state $sig = signature(
147 method => Object,
148 pos => [],
149 );
150 0 my ( $self ) = $sig->( @_ );
151 0 state $palette = TPalette->new( data => cpLabel, size => length( cpLabel ) );
152 0 return $palette->clone();
153 }
154
155 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=11 SCAR=46.7
Pod documented
156 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
157 0 state $sig = signature(
158 method => Object,
159 pos => [Object],
160 );
161 0 my ( $self, $event ) = $sig->( @_ );
162
163 0 $self->SUPER::handleEvent( $event );
164 0 ▶ if ( $event->{what} == evMouseDown ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($event->{'what'} == 1) { } 0 0 0
elsif ($event->{'what'} == 16) { } 0 0 0
elsif ($event->{'what'} == 512 and $self->{'link'} and $event->{'message'}{'command'} == 50 || $event->{'message'}{'command'} == 51) { } 0 0 0
165 0 $self->$focusLink( $event );
166 }
167 elsif ( $event->{what} == evKeyDown ) {
168 0 my $c = hotKey( $self->{text} );
169 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&getAltCode($c) == $event->{"keyDown"}{"keyCode"} or $c and $self->{"owner"}{"phase"} == 2 and uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c) 0 0 0
Condition0%0/9
&getAltCode($c) == $event->{"keyDown"}{"keyCode"} or $c and $self->{"owner"}{"phase"} == 2 and uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c
l!l&&r!l&&!r
000
$c and $self->{"owner"}{"phase"} == 2 and uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c
!ll&&!rl&&r
000
$c and $self->{"owner"}{"phase"} == 2
!ll&&!rl&&r
000
MC/DC0%0/4
&getAltCode($c) == $event->{"keyDown"}{"keyCode"} or $c and $self->{"owner"}{"phase"} == 2 and uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c
&getAltCode($c) == $event->{"keyDown"}{"keyCode"} $c $self->{"owner"}{"phase"} == 2 uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c
Truth table0%0/5
A or B and C and D
A= &getAltCode($c) == $event->{"keyDown"}{"keyCode"}B= $cC= $self->{"owner"}{"phase"} == 2D= uc $event->{"keyDown"}{"charScan"}{"charCode"} eq $c
ABCDresult
1XXX1
01111
00XX0
010X0
01100
170 getAltCode( $c ) == $event->{keyDown}{keyCode}
171 || ( $c
172 && $self->{owner}{phase} == phPostProcess
173 && uc( $event->{keyDown}{charScan}{charCode} ) eq $c )
174 ) {
175 0 $self->$focusLink( $event );
176 }
177 } #/ elsif ( $event->{what} ==...)
178 ▶ elsif (
Condition0%0/9
$event->{"what"} == 512 and $self->{"link"} and $event->{"message"}{"command"} == 50 || $event->{"message"}{"command"} == 51
!ll&&!rl&&r
000
$event->{"what"} == 512 and $self->{"link"}
!ll&&!rl&&r
000
$event->{"message"}{"command"} == 50 or $event->{"message"}{"command"} == 51
l!l&&r!l&&!r
000
MC/DC0%0/4
$event->{"what"} == 512 and $self->{"link"} and $event->{"message"}{"command"} == 50 || $event->{"message"}{"command"} == 51
$event->{"what"} == 512 $self->{"link"} $event->{"message"}{"command"} == 50 $event->{"message"}{"command"} == 51
Truth table0%0/5
A and B and C or D
A= $event->{"what"} == 512B= $self->{"link"}C= $event->{"message"}{"command"} == 50D= $event->{"message"}{"command"} == 51
ABCDresult
0XXX0
10XX0
11000
111X1
11011
179 $event->{what} == evBroadcast && $self->{link}
180 && ( $event->{message}{command} == cmReceivedFocus
181 || $event->{message}{command} == cmReleasedFocus )
182 ) {
183 0 $self->{light} = ( $self->{link}{state} & sfFocused ) != 0;
184 0 $self->drawView();
185 } #/ elsif ( $event->{what} ==...)
186 0 return;
187 } #/ sub handleEvent
188
189 0 ▶$focusLink = sub { # void ($event)
Subroutine __ANON__: not called CC=6 SCAR=37.4
190 0 my ( $self, $event ) = @_;
191 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
192 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
193 0 ▶ assert ( is_Object $event );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($event) 0 0 0
194 0 ▶ if ( $self->{link} && ( $self->{link}{options} & ofSelectable ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"link"} and $self->{"link"}{"options"} & 1) 0 0 0
Condition0%0/3
$self->{"link"} and $self->{"link"}{"options"} & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"link"} and $self->{"link"}{"options"} & 1
$self->{"link"} $self->{"link"}{"options"} & 1
Truth table0%0/3
A and B
A= $self->{"link"}B= $self->{"link"}{"options"} & 1
ABresult
0X0
100
111
195 0 $self->{link}->focus();
196 }
197 0 $self->clearEvent( $event );
198 0 return;
199 26 };
200
201 26 1
202
203 __END__
« lib/TUI/StdDlg/FileInputLine.pm ↑ Summary lib/TUI/StdDlg/Dir.pm »