Maker/Tee.pm

filter: Statementstmt 90.1% 82 / 91 Branchbran 53.5% 15 / 28 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 95.0% 19 / 20 Podpod 0.0% 0 / 3 totaltotal 77.7% 119 / 153 CC 18 SCAR 13.2
CC
18
Cov
79%
_new
7.3
PRINTF
7.1
cmpcache
5.1
CRAP 3.8
« Maker/Driver.pm ↑ Summary Maker/Path.pm »
1 package Config::Maker::Tee;
2  
3 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Symbol();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Tie::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use Config::Maker;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Config::Maker::Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use File::Basename 'dirname';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 our @ISA = qw(Tie::Handle);
16  
17 9 our $OUT = 1;
18 9 our $CACHE = 1;
19  
20 8 ▶sub _new {
Subroutine _new: called CC=6 SCAR=19.9
21 8 my ($class, $fh, $cache) = @_;
22 8 ▶ croak "No filehandle" unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 8 8
23 8 ▶ croak "No cache file" unless $cache;
Branch: 1 branch
BranchTrueFalseTotal
unless $cache 0 8 8
24 8 my $dir = dirname($cache);
25 8 ▶ unless(-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 8 8
26 0 require File::Path;
27 0 File::Path::mkpath($dir); # Throws on error
28 }
29 8 ▶ die "Can't write to cache dir $dir" unless -w $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -w $dir 0 8 8
30 8 ▶ my $self = bless Symbol::gensym(), ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
080
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
31 8 *$self->{fh} = $fh;
32 8 *$self->{cache} = '';
33 8 *$self->{file} = $cache;
34 8 return $self;
35 }
36  
37 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
38 8 my $self = shift->_new(@_);
39 8 tie *$self, $self;
40 8 return $self;
41 }
42  
43 8 ▶sub cmpcache {
Subroutine cmpcache: called CC=5 SCAR=16.3
Pod undocumented
44 8 my ($self) = @_;
45 8 ▶ unless(-e *$self->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e *$self->{"file"}) 1 7 8
46 1 ▶ DBG "Cache compare result: " . (*$self->{cache} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
*$self->{'cache'} ? : 1 0 1
47 1 ▶ return *$self->{cache} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
*$self->{'cache'} ? : 1 0 1
48 }
49 7 local $/;
50 7 ▶ open CACHE, '<'.$utf8, *$self->{file} or die "Can't read ".*$self->{file}.": $!";
Branch: 1 branch
BranchTrueFalseTotal
open CACHE, '<' . $Config::Maker::Tee::utf8, *$self->{"file"} or die q[Can't read ] . *$self->{"file"} . ": $!" 7 0 7
51 7 my $desired = <CACHE>;
52 7 close CACHE;
53 7 DBG "Cache compare result: " . ($desired eq *$self->{cache});
54 7 return $desired eq *$self->{cache};
55 }
56  
57 4 ▶sub savecache {
Subroutine savecache: called CC=2 SCAR=7.0
Pod undocumented
58 4 my ($self) = @_;
59 4 unlink *$self->{file}; # Don't rewrite; replace.
60 4 ▶ open CACHE, '>'.$utf8, *$self->{file} or die "Can't write ".*$self->{file}.": $!";
Branch: 1 branch
BranchTrueFalseTotal
open CACHE, '>' . $Config::Maker::Tee::utf8, *$self->{"file"} or die q[Can't write ] . *$self->{"file"} . ": $!" 4 0 4
61 4 local $,;
62 4 local $\;
63 4 print CACHE *$self->{cache};
64 4 close CACHE;
65 }
66  
67 8 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=2 SCAR=9.2
68 8 ▶ return $_[0] if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 8 0 8
69 0 return shift->_new(@_);
70 }
71  
72 12 ▶sub PRINT {
Subroutine PRINT: called CC=5 SCAR=16.2
73 9 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 12 my $self = shift;
75 12 ▶ my $ofs = $, || '';
Condition50%1/2
$, || ''
l!l
012
MC/DC0%0/1
$, || ''
$,
Truth table50%1/2
A
A= $,
Aresult
11
00
76 12 ▶ my $ors = $\ || '';
Condition50%1/2
$\ || ''
l!l
012
MC/DC0%0/1
$\ || ''
$\
Truth table50%1/2
A
A= $\
Aresult
11
00
77 12 DBG "PRINT: cache = $CACHE, out = $OUT, args = ".join(', ', @_);
78 12 ▶ *$self->{cache} .= join($ofs, @_) . $ors if $CACHE;
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Maker::Tee::CACHE 8 4 12
79 12 ▶ return unless $OUT;
Branch: 1 branch
BranchTrueFalseTotal
unless $Config::Maker::Tee::OUT 2 10 12
80 # *$self->{fh}->print(@_);
81 10 my $fh = *$self->{fh};
82 10 print $fh @_;
83 }
84  
85 0 ▶sub PRINTF {
Subroutine PRINTF: not called CC=3 SCAR=19.6
86 9 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
87 0 my $self = shift;
88 0 DBG "PRINTF: cache = $CACHE, out = $OUT, args = ".join(', ', @_);
89 0 ▶ *$self->{cache} .= sprintf(@_) if $CACHE;
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Maker::Tee::CACHE 0 0 0
90 0 ▶ return unless $OUT;
Branch: 1 branch
BranchTrueFalseTotal
unless $Config::Maker::Tee::OUT 0 0 0
91 # *$self->{fh}->printf(@_);
92 0 my $fh = *$self->{fh};
93 0 printf $fh @_;
94 }
95  
96 8 ▶sub CLOSE {
Subroutine CLOSE: called CC=1 SCAR=0.0
97 8 my $self = shift;
98 8 close *$self->{fh};
99 8 undef *$self->{fh};
100 }
101  
102 8 ▶sub BINMODE {
Subroutine BINMODE: called CC=1 SCAR=0.0
103 8 my $self = shift;
104 8 binmode *$self->{fh}, $_[0];
105 }
106  
107 9 1;
108  
109 __END__
« Maker/Driver.pm ↑ Summary Maker/Path.pm »