| 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
| |||||||||||||||||||||
| 23 | 8 | ▶ | croak "No cache file" unless $cache; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 8 | my $dir = dirname($cache); | |||||||||||||||||||
| 25 | 8 | ▶ | unless(-d $dir) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 30 | 8 | ▶ | my $self = bless Symbol::gensym(), ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 46 | 1 | ▶ | DBG "Cache compare result: " . (*$self->{cache} ? 0 : 1); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 1 | ▶ | return *$self->{cache} ? 0 : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 7 | local $/; | |||||||||||||||||||
| 50 | 7 | ▶ | open CACHE, '<'.$utf8, *$self->{file} or die "Can't read ".*$self->{file}.": $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
$, || ''
MC/DC0%0/1
$, || ''
$,
Truth table50%1/2
A
A= $,
| |||||||||||||||||||||
| 76 | 12 | ▶ | my $ors = $\ || ''; | ||||||||||||||||||
|
Condition50%1/2
$\ || ''
MC/DC0%0/1
$\ || ''
$\
Truth table50%1/2
A
A= $\
| |||||||||||||||||||||
| 77 | 12 | DBG "PRINT: cache = $CACHE, out = $OUT, args = ".join(', ', @_); | |||||||||||||||||||
| 78 | 12 | ▶ | *$self->{cache} .= join($ofs, @_) . $ors if $CACHE; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 12 | ▶ | return unless $OUT; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 90 | 0 | ▶ | return unless $OUT; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||