ParallelSubtest/Capture.pm

filter: Statementstmt 74.5% 41 / 55 Branchbran 14.2% 2 / 14 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 59.6% 59 / 99 CC 12 SCAR 25.9
CC
12
Cov
58%
replay_writes
42.0
new
5.6
TIEHANDLE
2.3
CRAP 13.3
↑ Summary ParallelSubtest.pm »
1 package Test::ParallelSubtest::Capture;
2 224 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 224 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 224 our $VERSION = '0.05';
6 224 $VERSION = eval $VERSION;
7  
8 {
9 package Test::ParallelSubtest::CaptureFH;
10 224 ▶ use IO::WrapTie;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 224 ▶ use Tie::FileHandle::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 224 our @ISA = qw(IO::WrapTie::Slave Tie::FileHandle::Base);
13  
14 264 ▶ sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=2 SCAR=8.1
15 264 my ($pkg, $bufref, $prefix) = @_;
16  
17 264 ▶ return bless {
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
02640
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
18 BufRef => $bufref,
19 Prefix => $prefix,
20 }, ref($pkg)||$pkg;
21 }
22  
23 541 ▶ sub PRINT {
Subroutine PRINT: called CC=2 SCAR=7.0
24 541 my $self = shift;
25  
26 541 my $text = join '', @_;
27 541 ▶ if (length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 541 0 541
28 # Append to the buffer the prefix that identifies this
29 # filehandle, followed by the data length and then the data.
30 541 ${ $self->{BufRef} } .= $self->{Prefix}
31 541 . pack('N', length $text) . $text;
32 }
33 }
34 }
35  
36 224 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 88 ▶sub new {
Subroutine new: called CC=4 SCAR=17.2
Pod documented
39 88 my ($pkg, $bufref) = @_;
40  
41 88 ▶ if ($bufref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bufref) { } 0 88 88
42 0 ▶ ref $bufref eq 'SCALAR' or croak 'new() arg must be a scalar ref';
Branch: 1 branch
BranchTrueFalseTotal
ref $bufref eq "SCALAR" or croak("new() arg must be a scalar ref") 0 0 0
43 }
44 else {
45 88 my $buf = '';
46 88 $bufref = \$buf;
47 }
48  
49 88 ▶ return bless {
Condition33%1/3
ref $pkg || $pkg
l!l&&r!l&&!r
0880
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
50 BufRef => $bufref,
51 }, ref($pkg)||$pkg;
52 }
53  
54 88 ▶sub install {
Subroutine install: called CC=2 SCAR=6.9
Pod documented
55 88 my ($self, $builder) = @_;
56  
57 88 my %fh;
58 88 foreach my $prefix (qw( o f t )) {
59 $fh{$prefix} = Test::ParallelSubtest::CaptureFH->new_tie(
60 264 $self->{BufRef}, $prefix);
61 }
62  
63 88 $builder->output( $fh{'o'});
64 88 $builder->failure_output($fh{'f'});
65 88 $builder->todo_output( $fh{'t'});
66 }
67  
68 88 ▶sub as_string_ref {
Subroutine as_string_ref: called CC=1 SCAR=0.0
Pod documented
69 88 my $self = shift;
70  
71 88 return $self->{BufRef};
72 }
73  
74 0 ▶sub replay_writes {
Subroutine replay_writes: not called CC=6 SCAR=37.4
Pod documented
75 0 my ($self, $out_dest, $fail_dest, $todo_dest) = @_;
76  
77 0 my %fh = (
78 'o' => $out_dest,
79 'f' => $fail_dest,
80 't' => $todo_dest,
81 );
82  
83 0 my $buf = ${ $self->{BufRef} };
84 0 ▶ while (length $buf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $buf) 0 0 0
85 0 ▶ $buf =~ s/^([oft])// or return;
Branch: 1 branch
BranchTrueFalseTotal
$buf =~ s/^([oft])// or return 0 0 0
86 0 my $fh = $fh{$1};
87 0 my $packed_len = substr $buf, 0, 4, '';
88 0 ▶ return if length($packed_len) != 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $packed_len != 4 0 0 0
89 0 my $len = unpack 'N', $packed_len;
90 0 ▶ return if $len < 1 or $len > length $buf;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 1 or $len > length $buf 0 0 0
Condition0%0/3
$len < 1 or $len > length $buf
l!l&&r!l&&!r
000
MC/DC0%0/2
$len < 1 or $len > length $buf
$len < 1 $len > length $buf
Truth table0%0/3
A or B
A= $len < 1B= $len > length $buf
ABresult
1X1
011
000
91 0 print $fh substr $buf, 0, $len, '';
92 }
93  
94 0 return 1;
95 }
96  
97 224 1;
98  
99 __END__
↑ Summary ParallelSubtest.pm »