lib/TUI/Dialogs/History.pm

filter: Statementstmt 43.0% 71 / 165 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 58.3% 21 / 36 Podpod 69.2% 9 / 13 totaltotal 39.1% 101 / 258 CC 17 SCAR 35.4
CC
17
Cov
35%
handleEvent
136.7
build
20.0
BUILD
12.0
CRAP 34.6
« lib/TUI/Views/Group.pm ↑ Summary lib/TUI/StdDlg/Dir.pm »
1 package TUI::Dialogs::History;
2 # ABSTRACT: A TWindow-based history browser for input controls
3
4 10 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 10 our $VERSION = '2.000003';
10 10 $VERSION =~ tr/_//d;
11 10 our $AUTHORITY = 'cpan:BRICKPOOL';
12
13 10 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 our @EXPORT = qw(
15 THistory
16 new_THistory
17 );
18
19 10 ▶use Encode qw( encode );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 10 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 10 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 is_Object
24 :types
25 10 );
26
27 10 ▶use TUI::Dialogs::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 cmRecordHistory
29 cpHistory
30 10 );
31 10 ▶use TUI::Dialogs::HistoryViewer::HistList qw( historyAdd );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 10 ▶use TUI::Dialogs::HistoryWindow;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 10 ▶use TUI::Dialogs::InputLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 10 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
35 :evXXXX
36 kbDown
37 10 );
38 10 ▶use TUI::Drivers::Util qw( ctrlToArrow );
Subroutine BEGIN: called CC=1 SCAR=0.0
39 10 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 10 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
41 cmOK
42 cmReleasedFocus
43 ofPostProcess
44 sfFocused
45 10 );
46 10 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 10 ▶use TUI::Views::Palette;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 10 ▶use TUI::Views::View;
Subroutine BEGIN: called CC=1 SCAR=0.0
49
50 sub THistory() { __PACKAGE__ }
51 sub name() { 'THistory' }
52 0 ▶sub new_THistory { __PACKAGE__->from(@_) }
Subroutine new_THistory: not called CC=1 SCAR=6.9
Pod documented
53
54 10 extends TView;
55
56 # declare global variables
57 10 our $icon = "\xDE~\x19~\xDD"; # cp437: "▐~↓~▌"
58 # our $icon = encode( cp437 => "▐~↓~▌" );
59
60 # protected attributes
61 0 ▶has link => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
62 0 ▶has historyId => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
63
64 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
65 0 state $sig = signature(
66 method => 1,
67 named => [
68 bounds => Object,
69 link => Object, { alias => 'aLink' },
70 historyId => PositiveOrZeroInt, { alias => 'aHistoryId' },
71 ],
72 caller_level => +1,
73 );
74 0 my ( $class, $args ) = $sig->( @_ );
75 0 return { %$args };
76 }
77
78 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
79 0 my ( $self, $args ) = @_;
80 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
81 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
82 0 $self->{options} |= ofPostProcess;
83 0 $self->{eventMask} |= evBroadcast;
84 0 return;
85 }
86
87 0 ▶sub from { # $obj ($bounds, $aLink, $aHistoryId)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
88 0 state $sig = signature(
89 method => 1,
90 pos => [Object, Object, PositiveOrZeroInt],
91 );
92 0 my ( $class, @args ) = $sig->( @_ );
93 0 return $class->new( bounds => $args[0], link => $args[1],
94 historyId => $args[2] );
95 }
96
97 0 ▶sub draw { # void ()
Subroutine draw: not called CC=1 SCAR=6.9
Pod documented
98 0 state $sig = signature(
99 method => Object,
100 pos => [],
101 );
102 0 my ( $self ) = $sig->( @_ );
103 0 my $b = TDrawBuffer->new();
104 0 $b->moveCStr( 0, $icon, $self->getColor( 0x0102 ) );
105 0 $self->writeLine( 0, 0, $self->{size}{x}, $self->{size}{y}, $b );
106 0 return;
107 }
108
109 0 ▶sub getPalette { # $palette ()
Subroutine getPalette: not called CC=1 SCAR=6.9
Pod documented
110 0 state $sig = signature(
111 method => Object,
112 pos => [],
113 );
114 0 my ( $self ) = $sig->( @_ );
115 0 state $palette = TPalette->new(
116 data => cpHistory,
117 size => length( cpHistory ),
118 );
119 0 return $palette->clone();
120 }
121
122 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=12 SCAR=49.2
Pod documented
123 0 state $sig = signature(
124 method => Object,
125 pos => [Object],
126 );
127 0 my ( $self, $event ) = $sig->( @_ );
128
129 0 my $historyWindow;
130 0 my ( $r, $p );
131 0 my $c;
132
133 0 $self->SUPER::handleEvent( $event );
134 0 ▶ if ( $event->{what} == evMouseDown
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{'what'} == 1 or $event->{'what'} == 16 and &ctrlToArrow($event->{'keyDown'}{'keyCode'}) == 20480 and $self->{'link'}{'state'} & 64) { } 0 0 0
Condition0%0/9
$event->{"what"} == 1 or $event->{"what"} == 16 and &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480 and $self->{"link"}{"state"} & 64
l!l&&r!l&&!r
000
$event->{"what"} == 16 and &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480 and $self->{"link"}{"state"} & 64
!ll&&!rl&&r
000
$event->{"what"} == 16 and &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480
!ll&&!rl&&r
000
MC/DC0%0/4
$event->{"what"} == 1 or $event->{"what"} == 16 and &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480 and $self->{"link"}{"state"} & 64
$event->{"what"} == 1 $event->{"what"} == 16 &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480 $self->{"link"}{"state"} & 64
Truth table0%0/5
A or B and C and D
A= $event->{"what"} == 1B= $event->{"what"} == 16C= &ctrlToArrow($event->{"keyDown"}{"keyCode"}) == 20480D= $self->{"link"}{"state"} & 64
ABCDresult
1XXX1
01111
00XX0
010X0
01100
135 || ( $event->{what} == evKeyDown
136 && ctrlToArrow( $event->{keyDown}{keyCode} ) == kbDown
137 && ( $self->{link}{state} & sfFocused ) )
138 ) {
139 0 ▶ if ( !$self->{link}->focus() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"link"}->focus) 0 0 0
140 0 $self->clearEvent( $event );
141 0 return;
142 }
143 0 $self->recordHistory( $self->{link}{data} );
144 0 $r = $self->{link}->getBounds();
145 0 $r->{a}{x}--;
146 0 $r->{b}{x}++;
147 0 $r->{b}{y} += 7;
148 0 $r->{a}{y}--;
149 0 $p = $self->{owner}->getExtent();
150 0 $r->intersect( $p );
151 0 $r->{b}{y}--;
152 0 $historyWindow = $self->initHistoryWindow( $r );
153
154 0 ▶ if ( $historyWindow != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($historyWindow != 0) 0 0 0
155 0 $c = $self->{owner}->execView( $historyWindow );
156 0 ▶ if ( $c == cmOK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c == 10) 0 0 0
157 0 my $rslt;
158 0 $historyWindow->getSelection( \$rslt );
159 0 $self->{link}{data} = substr( $rslt, 0, $self->{link}{maxLen} );
160 0 $self->{link}->selectAll( true );
161 0 $self->{link}->drawView();
162 }
163 0 $self->destroy( $historyWindow );
164 } #/ if ( $historyWindow !=...)
165 0 $self->clearEvent( $event );
166 }
167 else {
168 0 ▶ if ( $event->{what} == evBroadcast ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 512) 0 0 0
169 10 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
170 0 ▶ if ( ( $event->{message}{command} == cmReleasedFocus
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"message"}{"command"} == 51 and $event->{"message"}{"infoPtr"} == $self->{"link"} or $event->{"message"}{"command"} == 60) 0 0 0
Condition0%0/6
$event->{"message"}{"command"} == 51 and $event->{"message"}{"infoPtr"} == $self->{"link"} or $event->{"message"}{"command"} == 60
l!l&&r!l&&!r
000
$event->{"message"}{"command"} == 51 and $event->{"message"}{"infoPtr"} == $self->{"link"}
!ll&&!rl&&r
000
MC/DC0%0/3
$event->{"message"}{"command"} == 51 and $event->{"message"}{"infoPtr"} == $self->{"link"} or $event->{"message"}{"command"} == 60
$event->{"message"}{"command"} == 51 $event->{"message"}{"infoPtr"} == $self->{"link"} $event->{"message"}{"command"} == 60
Truth table0%0/5
A and B or C
A= $event->{"message"}{"command"} == 51B= $event->{"message"}{"infoPtr"} == $self->{"link"}C= $event->{"message"}{"command"} == 60
ABCresult
11X1
0X11
1011
0X00
1000
171 && $event->{message}{infoPtr} == $self->{link} )
172 || $event->{message}{command} == cmRecordHistory
173 ) {
174 0 $self->recordHistory( $self->{link}{data} );
175 } #/ if ( ( $event->{message...}))
176 } #/ if ( $event->{what} ==...)
177 }
178 0 return;
179 }
180
181 0 ▶sub initHistoryWindow { # $historyWindow ($bounds)
Subroutine initHistoryWindow: not called CC=1 SCAR=6.9
Pod documented
182 0 state $sig = signature(
183 method => Object,
184 pos => [Object],
185 );
186 0 my ( $self, $bounds ) = $sig->( @_ );
187 my $p = THistoryWindow->new(
188 bounds => $bounds,
189 historyId => $self->{historyId},
190 0 );
191 0 $p->{helpCtx} = $self->{link}{helpCtx};
192 0 return $p;
193 }
194
195 0 ▶sub recordHistory { # void ($s)
Subroutine recordHistory: not called CC=1 SCAR=6.9
Pod documented
196 0 state $sig = signature(
197 method => Object,
198 pos => [Str],
199 );
200 0 my ( $self, $s ) = $sig->( @_ );
201 0 historyAdd( $self->{historyId}, $s );
202 0 return;
203 }
204
205 0 ▶sub shutDown { # void ()
Subroutine shutDown: not called CC=1 SCAR=6.9
Pod documented
206 0 state $sig = signature(
207 method => Object,
208 pos => [],
209 );
210 0 my ( $self ) = $sig->( @_ );
211 0 $self->{link} = undef;
212 0 $self->SUPER::shutDown();
213 0 return;
214 }
215
216 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
217 0 state $sig = signature(
218 method => Object,
219 pos => [Object],
220 );
221 0 my ( $self, $os ) = $sig->( @_ );
222 0 $self->SUPER::write( $os );
223 0 $os->put( $self->{link}, $self->{historyId} );
224 0 return;
225 }
226
227 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
228 0 state $sig = signature(
229 method => Object,
230 pos => [Object],
231 );
232 0 my ( $self, $is ) = $sig->( @_ );
233 0 $self->SUPER::read( $is );
234 0 $self->{link} = $is->get();
235 0 $self->{historyId} = $is->get();
236 0 return $self;
237 }
238
239 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
240 0 my ( $class ) = @_;
241 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
242 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->is_Str 0 0 0
243 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
244 0 return $class->new(
245 bounds => TRect->new(),
246 link => TInputLine->build(),
247 historyId => 0,
248 );
249 }
250
251 10 1
252
253 __END__
« lib/TUI/Views/Group.pm ↑ Summary lib/TUI/StdDlg/Dir.pm »