blib/lib/Tie/Handle/TtyRec.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 66.6% 4 / 6 Conditioncond 62.5% 5 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 1 totaltotal 83.1% 59 / 71 CC 8 SCAR 9.9
CC
8
Cov
89%
TIEHANDLE
5.6
WRITE
3.0
READ
2.0
CRAP 2.7
↑ Summary
1 package Tie::Handle::TtyRec;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use base 'Tie::Handle';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Time::HiRes 'gettimeofday';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $VERSION = '0.04';
11  
12 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 4 my ($class, $filename, %params) = @_;
14 4 my $symbol = Symbol::gensym;
15  
16 4 tie(*$symbol, __PACKAGE__, $filename, %params);
17  
18 4 return $symbol;
19 }
20  
21 4 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=5 SCAR=17.2
22 4 my ($class, $filename, %params) = @_;
23  
24 my $mode = -p $filename ? '+>'
25 4 ▶ : $params{append} ? '>>'
Branch: 2 branches
BranchTrueFalseTotal
-p $filename ? : 0 4 4
$params{'append'} ? : 1 3 4
26 : '>';
27  
28 4 ▶ open(my $self, $mode, $filename)
Branch: 1 branch
BranchTrueFalseTotal
open my $self, $mode, $filename or croak("Unable to open $filename for writing: $!") 4 0 4
29 or croak "Unable to open $filename for writing: $!";
30  
31 4 $self->autoflush(1);
32  
33 4 ▶ bless $self, (ref $class || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
34 }
35  
36 0 ▶sub READ {
Subroutine READ: not called CC=1 SCAR=6.9
37 0 croak "Cannot read from a Tie::Handle::TtyRec";
38 }
39  
40 21 ▶sub WRITE {
Subroutine WRITE: called CC=3 SCAR=11.0
41 21 my $self = shift;
42 21 my ($buf, $length, $offset) = @_;
43 21 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
318
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
44 21 ▶ $length ||= length($buf) - $offset;
Condition66%2/3
$length ||= length($buf) - $offset
l!l&&r!l&&!r
9120
MC/DC0%0/2
$length ||= length($buf) - $offset
$length length($buf) - $offset
Truth table66%2/3
A ||= B
A= $lengthB= length($buf) - $offset
ABresult
1X1
011
000
45 21 syswrite $self, pack('VVV', gettimeofday, $length)
46 . substr($buf, $offset, $length);
47 }
48  
49 8 ▶sub PRINT {
Subroutine PRINT: called CC=2 SCAR=6.9
50 8 my $self = shift;
51 8 $self->WRITE($_) for @_;
52 }
53  
54 4 ▶sub CLOSE {
Subroutine CLOSE: called CC=1 SCAR=0.0
55 4 my $self = shift;
56 4 close $self;
57 }
58  
59 4 1;
60  
61 __END__
↑ Summary