SingleHandle.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 14 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 3 totaltotal 96.8% 91 / 94 CC 10 SCAR 12.1
CC
10
Cov
100%
TIEHANDLE
7.0
CLOSE
4.0
BEGIN
1.0
CRAP 3.3
↑ Summary DualHandle.pm »
1 #!perl
2 package # hide from pause
3 File::Replace::SingleHandle;
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Scalar::Util qw/blessed weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # For AUTHOR, COPYRIGHT, AND LICENSE see the bottom of this file
11  
12 2 our $VERSION = '0.18';
13  
14 ## no critic (RequireFinalReturn, RequireArgUnpacking)
15  
16 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 require Tie::Handle::Base;
18 2 our @ISA = qw/ Tie::Handle::Base /; ## no critic (ProhibitExplicitISA)
19 }
20  
21 37 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=7 SCAR=19.5
22 37 ▶ @_==3 or croak __PACKAGE__."->TIEHANDLE: bad number of args";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("File::Replace::SingleHandle->TIEHANDLE: bad number of args") 36 1 37
23 36 my ($class,$repl,$mode) = @_;
24 36 ▶ croak "$class->TIEHANDLE: argument must be a File::Replace object"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($repl) and $repl->isa("File::Replace") 2 34 36
Condition100%3/3
builtin::blessed($repl) and $repl->isa("File::Replace")
!ll&&!rl&&r
1134
MC/DC100%2/2
builtin::blessed($repl) and $repl->isa("File::Replace")
builtin::blessed($repl) $repl->isa("File::Replace")
Truth table100%3/3
A and B
A= builtin::blessed($repl)B= $repl->isa("File::Replace")
ABresult
0X0
100
111
25 unless blessed($repl) && $repl->isa('File::Replace');
26 34 my ($innerhandle,$other);
27 34 ▶ if ($mode eq 'in') {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq 'in') { } 15 19 34
elsif ($mode eq 'out') { } 15 4 19
elsif ($mode eq 'onlyout') { } 3 1 4
28 15 $innerhandle = $repl->in_fh;
29 15 $other = $repl->out_fh; }
30 elsif ($mode eq 'out') {
31 15 $innerhandle = $repl->out_fh;
32 15 $other = $repl->in_fh; }
33 elsif ($mode eq 'onlyout') {
34 3 $innerhandle = $repl->out_fh; }
35 1 else { croak "bad mode" }
36 33 my $self = $class->SUPER::TIEHANDLE($innerhandle);
37 33 $self->{repl} = $repl;
38 33 $self->{other} = $other;
39 33 weaken( $self->{other} );
40 33 return $self;
41 }
42  
43 9 ▶sub replace { return shift->{repl} }
Subroutine replace: called CC=1 SCAR=0.0
Pod undocumented
44 1 ▶sub in_fh { return shift->{repl}->in_fh }
Subroutine in_fh: called CC=1 SCAR=0.0
Pod undocumented
45 1 ▶sub out_fh { return shift->{repl}->out_fh }
Subroutine out_fh: called CC=1 SCAR=0.0
Pod undocumented
46  
47 1 ▶sub OPEN { croak "Can't reopen a ".ref($_[0])." handle" }
Subroutine OPEN: called CC=1 SCAR=0.0
48  
49 21 ▶sub CLOSE {
Subroutine CLOSE: called CC=4 SCAR=13.9
50 21 my $self = shift;
51 21 ▶ if ( defined($self->{other}) && defined(fileno($self->{other})) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'other'} and defined fileno $self->{'other'}) { } 10 11 21
Condition100%3/3
defined $self->{"other"} and defined fileno $self->{"other"}
!ll&&!rl&&r
3810
MC/DC100%2/2
defined $self->{"other"} and defined fileno $self->{"other"}
defined $self->{"other"} defined fileno $self->{"other"}
Truth table100%3/3
A and B
A= defined $self->{"other"}B= defined fileno $self->{"other"}
ABresult
0X0
100
111
52 # the other file is still open, so just close this one
53 10 ▶ my $rv = $self->SUPER::CLOSE()
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $self->SUPER::CLOSE or croak("couldn't close handle: $!") 8 2 10
54 or croak "couldn't close handle: $!";
55 8 return $rv;
56 }
57 else { # the other file is closed, trigger the replacement now
58 11 return !!$self->{repl}->finish }
59 }
60  
61 2 ▶sub UNTIE {
Subroutine UNTIE: called CC=1 SCAR=0.0
62 2 my $self = shift;
63 2 warnings::warnif("Please don't untie ".ref($self)." handles");
64 2 $self->{other} = undef;
65 2 $self->{repl} = undef;
66 2 $self->SUPER::UNTIE(@_);
67 }
68  
69 33 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
70 33 my $self = shift;
71 # File::Replace destructor will warn on unclosed file
72 33 $self->{other} = undef;
73 33 $self->{repl} = undef;
74 33 $self->SUPER::DESTROY(@_);
75 }
76  
77 2 1;
78 __END__
↑ Summary DualHandle.pm »