lib/TUI/TextView/TextDevice.pm

filter: Statementstmt 23.4% 33 / 141 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 12.5% 7 / 56 Podpod 80.5% 29 / 36 totaltotal 24.1% 69 / 286 CC 25 SCAR 22.1
CC
25
Cov
17%
DEMOLISH
42.0
__ANON__
30.0
syswrite
20.0
CRAP 9.1
« lib/TUI/toolkit/Types.pm ↑ Summary lib/TUI/Drivers/ScreenCell.pm »
1 package TUI::TextView::TextDevice;
2 # ABSTRACT: Abstract text device class
3
4 8 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 8 our $VERSION = '2.000002';
9 8 $VERSION =~ tr/_//d;
10 8 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 our @EXPORT = qw(
14 TTextDevice
15 new_TTextDevice
16 );
17
18 8 require bytes;
19 8 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 Maybe
22 :is
23 :types
24 8 );
25
26 8 ▶use TUI::Views::Scroller;
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28 sub TTextDevice() { __PACKAGE__ }
29 sub name() { 'TTextDevice' }
30 0 ▶sub new_TTextDevice { __PACKAGE__->from(@_) }
Subroutine new_TTextDevice: not called CC=1 SCAR=6.9
Pod documented
31
32 8 extends TScroller;
33
34 # protected attributes
35 8 has opened => ( is => 'ro', default => true );
36
37 # private attributes
38 8 has egress => ( is => 'bare', default => '' );
39 8 has esize => ( is => 'bare', default => 2048 );
40 8 has autoflush => ( is => 'bare', default => false );
41
42 # predeclare private methods
43 my (
44 8 $append_to_egress
45 );
46
47 # TTextDevice streambuf interface
48
49 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=6 SCAR=37.4
Pod documented
50 0 my ( $self, $in_global_destruction ) = @_;
51 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
52 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
53 0 ▶ assert ( is_Bool $in_global_destruction );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Bool($in_global_destruction) 0 0 0
54 0 ▶ unless ( $in_global_destruction ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_global_destruction) 0 0 0
55 0 ▶ $self->close()
Branch: 1 branch
BranchTrueFalseTotal
if $self->opened 0 0 0
56 if $self->opened();
57 }
58 0 return;
59 }
60
61 0 ▶sub do_sputn { # $num ($s, $count)
Subroutine do_sputn: not called CC=1 SCAR=6.9
Pod documented
62 0 state $sig = signature(
63 method => Object,
64 pos => [Str, Int],
65 );
66 0 $sig->( @_ );
67 ...
68 0 }
69
70 # B<Note>: only for compatibility
71 0 ▶sub overflow { # $int (|$c)
Subroutine overflow: not called CC=3 SCAR=24.8
Pod undocumented
72 0 state $sig = signature(
73 method => Object,
74 pos => [Maybe[Int]],
75 );
76 0 my ( $self, $c ) = $sig->( @_ );
77 0 ▶ $c //= -1;
Condition0%0/2
$c //= -1
l!l
00
MC/DC0%0/1
$c //= -1
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
78 0 ▶ if ( $c != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c != -1) 0 0 0
79 0 my $b = chr( $c );
80 0 $self->do_sputn( $b, 1 );
81 }
82 0 return 1;
83 }
84
85 # IO::Handle interface
86
87 # C<autoflush> getter/setter
88 # B<Note>: turn on autoflush if no argument is given.
89 0 ▶sub autoflush { # $ (|$)
Subroutine autoflush: not called CC=2 SCAR=17.9
Pod documented
90 0 state $sig = signature(
91 method => Object,
92 pos => [Maybe[Bool], { optional => 1 }],
93 );
94 0 my ( $self, $value ) = $sig->( @_ );
95 0 my $r = $self->{autoflush};
96 0 ▶ $self->{autoflush} = !!( @_ > 1 ? $value : 1 );
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
97 0 return $r;
98 }
99
100 0 ▶sub close { # $success ()
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
101 0 state $sig = signature(
102 method => Object,
103 pos => [],
104 );
105 0 my ( $self ) = $sig->( @_ );
106 0 ▶ return unless $self->opened();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->opened 0 0 0
107 0 my $r = $self->flush();
108 0 $self->{opened} = false;
109 0 return $r;
110 }
111
112 # C<flush> method: write buffer and clear it.
113 # Returns C<"0 but true"> on success, undef on error.
114 0 ▶sub flush { # $success ()
Subroutine flush: not called CC=3 SCAR=24.8
Pod documented
115 0 state $sig = signature(
116 method => Object,
117 pos => [],
118 );
119 0 my ( $self ) = $sig->( @_ );
120 0 ▶ return 1 unless length $self->{egress}; # Nothing to flush
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"egress"} 0 0 0
121 0 my $data = $self->{egress};
122 0 $self->{egress} = ''; # Clear buffer
123 0 ▶ return $self->syswrite( $data ) ? "0E0" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->syswrite($data) ? : 0 0 0
124 }
125
126 # Append data to the C<egress> buffer and L</flush> if size exceeds C<esize>
127 0 ▶$append_to_egress = sub { # void ($data)
Subroutine __ANON__: not called CC=5 SCAR=34.0
128 0 my ( $self, $data ) = @_;
129 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
130 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
131 0 ▶ assert ( is_Str $data );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($data) 0 0 0
132 0 $self->{egress} .= $data;
133
134 # Auto-flush if buffer exceeds esize
135 0 ▶ if ( bytes::length( $self->{egress} ) >= $self->{esize} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&bytes::length($self->{"egress"}) >= $self->{"esize"}) 0 0 0
136 0 $self->flush();
137 }
138 0 return;
139 8 };
140
141 0 ▶sub print { # $success (@list)
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
142 0 state $sig = signature(
143 method => Object,
144 pos => [
145 ArrayRef, { slurpy => 1 },
146 ],
147 );
148 0 my ( $self, $list ) = $sig->( @_ );
149 0 $self->$append_to_egress( join( '', @$list ) );
150 0 ▶ $self->flush() if $self->{autoflush};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"autoflush"} 0 0 0
151 0 return 1;
152 }
153
154 0 ▶sub printf { # $success ($format, @list)
Subroutine printf: not called CC=2 SCAR=17.9
Pod documented
155 0 state $sig = signature(
156 method => Object,
157 pos => [
158 Str,
159 ArrayRef, { slurpy => 1 },
160 ],
161 );
162 0 my ( $self, $format, $list ) = $sig->( @_ );
163 0 $self->$append_to_egress( sprintf( $format, @$list ) );
164 0 ▶ $self->flush() if $self->{autoflush};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"autoflush"} 0 0 0
165 0 return 1;
166 }
167
168 0 ▶sub printflush { # $success (@list)
Subroutine printflush: not called CC=1 SCAR=6.9
Pod documented
169 0 state $sig = signature(
170 method => Object,
171 pos => [
172 ArrayRef, { slurpy => 1 },
173 ],
174 );
175 0 my ( $self, $list ) = $sig->( @_ );
176 0 $self->$append_to_egress( join( '', @$list ) );
177 0 return $self->flush(); # Force flush right now
178 }
179
180 0 ▶sub say { # $success (@list)
Subroutine say: not called CC=2 SCAR=17.9
Pod documented
181 0 state $sig = signature(
182 method => Object,
183 pos => [
184 ArrayRef, { slurpy => 1 },
185 ],
186 );
187 0 my ( $self, $list ) = $sig->( @_ );
188 0 $self->$append_to_egress( join( '', @$list ) . "\n" );
189 0 ▶ $self->flush() if $self->{autoflush};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"autoflush"} 0 0 0
190 0 return 1;
191 }
192
193 # The C<syswrite> method in Perl is the equivalent of L</do_sputn> in
194 # Borland's RTL. We need to call L</do_sputn> here to replicate the original
195 # behavior.
196 0 ▶sub syswrite { # $num|undef ($, |$length, |$offset)
Subroutine syswrite: not called CC=4 SCAR=30.0
Pod documented
197 0 state $sig = signature(
198 method => Object,
199 pos => [
200 Str,
201 Int, { optional => 1 },
202 Int, { optional => 1 },
203 ],
204 );
205 0 my ( $self, $s, $len, $off ) = $sig->( @_ );
206 0 ▶ $len //= bytes::length( $s );
Condition0%0/3
$len //= &bytes::length($s)
l!l&&r!l&&!r
000
MC/DC0%0/2
$len //= &bytes::length($s)
$len &bytes::length($s)
Truth table0%0/3
A //= B
A= $lenB= &bytes::length($s)
ABresult
1X1
011
000
207 0 ▶ return $self->do_sputn(
Branch: 1 branch
BranchTrueFalseTotal
defined $len ? : 0 0 0
Condition0%0/2
$off || 0
l!l
00
MC/DC0%0/1
$off || 0
$off
Truth table0%0/2
A
A= $off
Aresult
11
00
208 (
209 defined( $len )
210 ? bytes::substr( $s, $off || 0, $len )
211 : $s
212 ),
213 $len
214 );
215 } #/ sub syswrite
216
217 # always true
218
219 0 ▶sub eof { 1 }
Subroutine eof: not called CC=1 SCAR=6.9
Pod documented
220 0 ▶sub ungetc { 1 }
Subroutine ungetc: not called CC=1 SCAR=6.9
Pod documented
221 0 ▶sub binmode { 1 }
Subroutine binmode: not called CC=1 SCAR=6.9
Pod documented
222
223 # always false
224
225 0 ▶sub getc { '' }
Subroutine getc: not called CC=1 SCAR=6.9
Pod documented
226 0 ▶sub read { '' }
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
227 0 ▶sub error { '' }
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
228 0 ▶sub getline { '' }
Subroutine getline: not called CC=1 SCAR=6.9
Pod documented
229
230 # abstract
231
232 0 ▶sub new_from_fd { ... }
Subroutine new_from_fd: not called CC=1 SCAR=6.9
Pod documented
233 0 ▶sub fdopen { ... }
Subroutine fdopen: not called CC=1 SCAR=6.9
Pod documented
234 0 ▶sub fcntl { ... }
Subroutine fcntl: not called CC=1 SCAR=6.9
Pod documented
235 0 ▶sub format_write { ... }
Subroutine format_write: not called CC=1 SCAR=6.9
Pod undocumented
236 0 ▶sub ioctl { ... }
Subroutine ioctl: not called CC=1 SCAR=6.9
Pod documented
237 0 ▶sub stat { ... }
Subroutine stat: not called CC=1 SCAR=6.9
Pod documented
238 0 ▶sub truncate { ... }
Subroutine truncate: not called CC=1 SCAR=6.9
Pod documented
239 0 ▶sub seek { ... }
Subroutine seek: not called CC=1 SCAR=6.9
Pod documented
240 0 ▶sub tell { ... }
Subroutine tell: not called CC=1 SCAR=6.9
Pod documented
241 0 ▶sub sync { ... }
Subroutine sync: not called CC=1 SCAR=6.9
Pod undocumented
242 0 ▶sub blocking { ... }
Subroutine blocking: not called CC=1 SCAR=6.9
Pod documented
243 0 ▶sub sysseek { ... }
Subroutine sysseek: not called CC=1 SCAR=6.9
Pod undocumented
244
245 # stubs for the other methods
246
247 0 ▶sub write { !!shift->syswrite(@_) }
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
248 0 ▶sub getlines { wantarray ? () : Carp::croak('called in a scalar context') }
Subroutine getlines: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
249 0 ▶sub fileno { -1 }
Subroutine fileno: not called CC=1 SCAR=6.9
Pod documented
250 0 ▶sub clearerr { 0 }
Subroutine clearerr: not called CC=1 SCAR=6.9
Pod documented
251 0 ▶sub sysread { 0 }
Subroutine sysread: not called CC=1 SCAR=6.9
Pod undocumented
252
253 # tiehandle interface
254
255 0 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: not called CC=2 SCAR=17.9
256 0 ▶ ref($_[0])
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
257 ? shift
258 : shift->new(@_)
259 }
260
261 0 ▶sub GETC { shift->getc(@_) }
Subroutine GETC: not called CC=1 SCAR=6.9
262 0 ▶sub PRINT { shift->print(@_) }
Subroutine PRINT: not called CC=1 SCAR=6.9
263 0 ▶sub PRINTF { shift->printf(@_) }
Subroutine PRINTF: not called CC=1 SCAR=6.9
264 0 ▶sub READ { shift->read(@_) }
Subroutine READ: not called CC=1 SCAR=6.9
265 0 ▶sub WRITE { shift->syswrite(@_) }
Subroutine WRITE: not called CC=1 SCAR=6.9
266 0 ▶sub SEEK { shift->seek(@_) }
Subroutine SEEK: not called CC=1 SCAR=6.9
267 0 ▶sub TELL { shift->tell(@_) }
Subroutine TELL: not called CC=1 SCAR=6.9
268 0 ▶sub EOF { shift->eof() }
Subroutine EOF: not called CC=1 SCAR=6.9
269 0 ▶sub CLOSE { shift->close(@_) }
Subroutine CLOSE: not called CC=1 SCAR=6.9
270 0 ▶sub BINMODE { shift->binmode(@_) }
Subroutine BINMODE: not called CC=1 SCAR=6.9
271
272 0 ▶sub READLINE {
Subroutine READLINE: not called CC=2 SCAR=17.9
273 wantarray
274 0 ▶ ? shift->getlines(@_)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
275 : shift->getline(@_)
276 }
277
278 8 1
279
280 __END__
« lib/TUI/toolkit/Types.pm ↑ Summary lib/TUI/Drivers/ScreenCell.pm »