lib/TUI/Views/DrawBuffer.pm

filter: Statementstmt 33.5% 57 / 170 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 45.4% 15 / 33 Podpod 70.0% 7 / 10 totaltotal 23.8% 79 / 331 CC 46 SCAR 36.7
CC
46
Cov
22%
moveChar
132.0
moveBuf
90.0
moveStr
56.0
CRAP 39.3
« lib/TUI/App/DeskTop.pm ↑ Summary lib/TUI/Views/Group.pm »
1 package TUI::Views::DrawBuffer;
2 # ABSTRACT: TDrawBuffer stores a line of text for output in views
3
4 95 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 95 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 95 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 95 our $VERSION = '2.000002';
9 95 $VERSION =~ tr/_//d;
10 95 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 95 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 95 our @EXPORT = qw(
14 TDrawBuffer
15 new_TDrawBuffer
16 );
17
18 95 ▶use List::Util qw( min max );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 95 ▶use TUI::toolkit qw( :utils );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 95 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 :is
22 :types
23 Maybe
24 95 );
25
26 95 ▶use TUI::Drivers::AttrPair;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 95 ▶use TUI::Drivers::ColorAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 95 ▶use TUI::Drivers::Screen;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 95 ▶use TUI::Drivers::ScreenCell;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 95 ▶use TUI::Views::Const qw( maxViewWidth );
Subroutine BEGIN: called CC=1 SCAR=0.0
31
32 sub TDrawBuffer() { __PACKAGE__ }
33 0 ▶sub new_TDrawBuffer { __PACKAGE__->from(@_) }
Subroutine new_TDrawBuffer: not called CC=1 SCAR=6.9
Pod undocumented
34
35 # import global variables
36 95 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
37 $screenHeight
38 $screenWidth
39 95 );
40 {
41 95 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 95 *screenHeight = \${ TScreen . '::screenHeight' };
43 95 *screenWidth = \${ TScreen . '::screenWidth' };
44 }
45
46 0 ▶my $getBufferLength = sub { # $num ()
Subroutine __ANON__: not called CC=2 SCAR=17.9
47 0 ▶ assert ( @_ == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 0 0
48 0 return max(
49 8 + max( $screenWidth, $screenHeight ),
50 maxViewWidth,
51 );
52 95 };
53
54 # macro for coercing a value into a TColorAttr object
55 0 ▶my $coerceAttr = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
56 0 ▶ return ref $_[0] ? $_[0] : TColorAttr->new( bios => $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
57 95 };
58
59 # macro for coercing a value into a TAttrPair object
60 0 ▶my $coerceAttrPair = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
61 0 ▶ return ref $_[0] ? $_[0] : TAttrPair->new( bios => $_[0] );
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
62 95 };
63
64 0 ▶sub new { # $obj ()
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
65 0 state $sig = signature(
66 method => 1,
67 pos => [],
68 );
69 0 my ( $class ) = $sig->( @_ );
70 0 return bless [], $class;
71 }
72
73 0 ▶sub from { # $obj ()
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
74 0 goto &new;
75 }
76
77 0 ▶sub putAttribute { # void ($indent, $attr)
Subroutine putAttribute: not called CC=3 SCAR=24.8
Pod documented
78 state $sig = signature(
79 method => Object,
80 pos => [
81 PositiveOrZeroInt,
82 0 ▶ sub { is_Object $_[0] or is_PositiveOrZeroInt $_[0] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
&is_Object($_[0]) or &is_PositiveOrZeroInt($_[0]) 0 0 0
83 0 ],
84 );
85 0 my ( $self, $indent, $attr ) = $sig->( @_ );
86 0 ▶ assert ( $indent < &$getBufferLength() );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent < &$getBufferLength() 0 0 0
87 0 ▶ my $cell = $self->[$indent] //= TScreenCell->new();
Condition0%0/3
$self->[$indent] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[$indent] //= "TUI::Drivers::ScreenCell"->new
$self->[$indent] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $self->[$indent]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
88 0 $cell->attribute( $attr );
89 0 return;
90 }
91
92 0 ▶sub putChar { # void ($indent, $ch)
Subroutine putChar: not called CC=4 SCAR=30.0
Pod documented
93 0 state $sig = signature(
94 method => Object,
95 pos => [PositiveOrZeroInt, Str],
96 );
97 0 my ( $self, $indent, $ch ) = $sig->( @_ );
98 0 ▶ assert ( length $ch );
Branch: 1 branch
BranchTrueFalseTotal
unless length $ch 0 0 0
99 0 ▶ assert ( $indent < &$getBufferLength() );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent < &$getBufferLength() 0 0 0
100 0 ▶ my $cell = $self->[$indent] //= TScreenCell->new();
Condition0%0/3
$self->[$indent] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[$indent] //= "TUI::Drivers::ScreenCell"->new
$self->[$indent] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $self->[$indent]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
101 0 $cell->character( $ch );
102 0 return;
103 }
104
105 0 ▶sub moveBuf { # void ($indent, \@source, $attr|undef, $count)
Subroutine moveBuf: not called CC=9 SCAR=45.0
Pod documented
106 state $sig = signature(
107 method => Object,
108 pos => [
109 PositiveOrZeroInt,
110 ArrayLike,
111 0 ▶ sub { !defined $_[0] or is_Object $_[0] or is_PositiveOrZeroInt $_[0] },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] or &is_Object($_[0]) or &is_PositiveOrZeroInt($_[0]) 0 0 0
Condition0%0/3
not defined $_[0] or &is_Object($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $_[0] or &is_Object($_[0])
not defined $_[0] &is_Object($_[0])
Truth table0%0/3
not(A) or B
A= not defined $_[0]B= &is_Object($_[0])
ABresult
1X1
011
000
112 0 PositiveOrZeroInt,
113 ],
114 );
115 0 my ( $self, $indent, $source, $attr, $count ) = $sig->( @_ );
116 0 ▶ assert ( $indent + $count <= &$getBufferLength() );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent + $count <= &$getBufferLength() 0 0 0
117
118 0 ▶ if ( defined $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) { } 0 0 0
119 0 $attr = $attr->$coerceAttr();
120 0 ▶ for ( my $i = 0 ; $i < $count ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 0 0
121 0 my $c = $source->[$i];
122 0 ▶ my $cell = $self->[ $indent + $i ] //= TScreenCell->new();
Condition0%0/3
$$self[$indent + $i] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$indent + $i] //= "TUI::Drivers::ScreenCell"->new
$$self[$indent + $i] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$indent + $i]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
123 0 ▶ $cell->character( ref $c ? $c->character() : chr( $c ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $c ? : 0 0 0
124 0 $cell->attribute( $attr );
125 }
126 }
127 else {
128 0 ▶ for ( my $i = 0 ; $i < $count ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 0 0
129 0 my $c = $source->[$i];
130 0 ▶ my $cell = $self->[ $indent + $i ] //= TScreenCell->new();
Condition0%0/3
$$self[$indent + $i] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$indent + $i] //= "TUI::Drivers::ScreenCell"->new
$$self[$indent + $i] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$indent + $i]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
131 0 ▶ if ( ref $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c) { } 0 0 0
132 0 $cell->assign( $c );
133 }
134 else {
135 0 my ( $ch, $cellAttr ) = unpack 'aC' => pack 'v' => $c;
136 0 $cell->character( $ch );
137 0 $cell->attribute( $cellAttr );
138 }
139 }
140 }
141 0 return;
142 } #/ sub moveBuf
143
144 0 ▶sub moveChar { # void ($indent, $c|undef, $attr|undef, $count)
Subroutine moveChar: not called CC=11 SCAR=48.8
Pod documented
145 state $sig = signature(
146 method => Object,
147 pos => [
148 PositiveOrZeroInt,
149 Maybe[Str],
150 0 ▶ sub { !defined $_[0] or is_Object $_[0] or is_PositiveOrZeroInt $_[0] },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] or &is_Object($_[0]) or &is_PositiveOrZeroInt($_[0]) 0 0 0
Condition0%0/3
not defined $_[0] or &is_Object($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $_[0] or &is_Object($_[0])
not defined $_[0] &is_Object($_[0])
Truth table0%0/3
not(A) or B
A= not defined $_[0]B= &is_Object($_[0])
ABresult
1X1
011
000
151 0 PositiveOrZeroInt,
152 ],
153 );
154 0 my ( $self, $indent, $c, $attr, $count ) = $sig->( @_ );
155 0 ▶ assert ( $indent + $count <= &$getBufferLength() );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent + $count <= &$getBufferLength() 0 0 0
156
157 0 my $dest = $indent;
158 0 ▶ if ( defined $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) { } 0 0 0
159 0 $attr = $attr->$coerceAttr(); # only for performance
160 0 ▶ if ( defined $c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) { } 0 0 0
161 0 for ( 1 .. $count ) {
162 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
163 0 $cell->character( $c );
164 0 $cell->attribute( $attr );
165 }
166 }
167 else {
168 0 for ( 1 .. $count ) {
169 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
170 0 $cell->attribute( $attr );
171 }
172 }
173 }
174 0 else {
175 0 ▶ assert ( length $c );
Branch: 1 branch
BranchTrueFalseTotal
unless length $c 0 0 0
176 0 for ( 1 .. $count ) {
177 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
178 0 $cell->character( $c );
179 }
180 }
181 0 return;
182 } #/ sub moveChar
183
184 0 ▶sub moveCStr { # $num ($indent, $str, $attrs)
Subroutine moveCStr: not called CC=4 SCAR=30.0
Pod documented
185 state $sig = signature(
186 method => Object,
187 pos => [
188 PositiveOrZeroInt,
189 Str,
190 0 ▶ sub { is_ArrayLike $_[0] or is_PositiveOrZeroInt $_[0] },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
&is_ArrayLike($_[0]) or &is_PositiveOrZeroInt($_[0]) 0 0 0
191 0 ],
192 );
193 0 my ( $self, $indent, $str, $attrs ) = $sig->( @_ );
194
195 0 my $dest = $indent;
196 0 my $toggle = 1;
197 0 $attrs = $attrs->$coerceAttrPair();
198 0 my $curAttr = $attrs->[0];
199
200 0 foreach my $ch ( split //, $str ) {
201 0 ▶ if ( $ch eq '~' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq '~') { } 0 0 0
202 0 $curAttr = $attrs->[$toggle];
203 0 $toggle = 1 - $toggle;
204 }
205 else {
206 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
207 0 $cell->character( $ch );
208 0 $cell->attribute( $curAttr );
209 }
210 }
211 0 return $dest - $indent;
212 } #/ sub moveCStr
213
214 0 ▶sub moveStr { # $num ($indent, $str, $attr|undef)
Subroutine moveStr: not called CC=7 SCAR=40.3
Pod documented
215 state $sig = signature(
216 method => Object,
217 pos => [
218 PositiveOrZeroInt,
219 Str,
220 0 ▶ sub { !defined $_[0] or is_Object $_[0] or is_PositiveOrZeroInt $_[0] },
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] or &is_Object($_[0]) or &is_PositiveOrZeroInt($_[0]) 0 0 0
Condition0%0/3
not defined $_[0] or &is_Object($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $_[0] or &is_Object($_[0])
not defined $_[0] &is_Object($_[0])
Truth table0%0/3
not(A) or B
A= not defined $_[0]B= &is_Object($_[0])
ABresult
1X1
011
000
221 0 ],
222 );
223 0 my ( $self, $indent, $str, $attr ) = $sig->( @_ );
224
225 0 my @chars = split //, $str;
226 0 ▶ assert ( $indent + @chars <= &$getBufferLength() );
Branch: 1 branch
BranchTrueFalseTotal
unless $indent + @chars <= &$getBufferLength() 0 0 0
227
228 0 my $dest = $indent;
229 0 ▶ if ( defined $attr ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attr) { } 0 0 0
230 0 $attr = $attr->$coerceAttr();
231 0 for my $ch ( @chars ) {
232 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
233 0 $cell->character( $ch );
234 0 $cell->attribute( $attr );
235 }
236 }
237 else {
238 0 for my $ch ( @chars ) {
239 0 ▶ my $cell = $self->[$dest++] //= TScreenCell->new();
Condition0%0/3
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self[$dest++] //= "TUI::Drivers::ScreenCell"->new
$$self[$dest++] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $$self[$dest++]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
240 0 $cell->character( $ch );
241 }
242 }
243 0 return scalar @chars;
244 }
245
246 0 ▶sub dump { # $str (|$maxLength)
Subroutine dump: not called CC=3 SCAR=20.8
Pod undocumented
247 0 state $sig = signature(
248 method => Object,
249 pos => [
250 PositiveOrZeroInt, { default => 5 },
251 ],
252 );
253 0 my ( $self, $maxLength ) = $sig->( @_ );
254
255 0 $maxLength = max( $maxLength, &$getBufferLength() );
256 0 my @cells;
257 0 for my $i ( 0 .. $maxLength - 1 ) {
258 0 ▶ my $cell = $self->[$i] //= TScreenCell->new();
Condition0%0/3
$self->[$i] //= "TUI::Drivers::ScreenCell"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[$i] //= "TUI::Drivers::ScreenCell"->new
$self->[$i] "TUI::Drivers::ScreenCell"->new
Truth table0%0/3
A //= B
A= $self->[$i]B= "TUI::Drivers::ScreenCell"->new
ABresult
1X1
011
000
259 0 push @cells, sprintf(
260 '%d:%s',
261 $cell->attribute()->toBIOS(),
262 $cell->character()->getText(),
263 );
264 }
265
266 95 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
267 0 require Data::Dumper;
268 0 my $str = Data::Dumper::Dumper( \@cells );
269 0 $str =~ s/(^|\s)\$VAR\d+\b/$1'$self'/g;
270 0 return $str;
271 }
272
273 95 1
274
275 __END__
« lib/TUI/App/DeskTop.pm ↑ Summary lib/TUI/Views/Group.pm »