DualHandle.pm

filter: Statementstmt 100% 53 / 53 Branchbran 100% 14 / 14 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 3 totaltotal 97.2% 104 / 107 CC 12 SCAR 9.7
CC
12
Cov
100%
OPEN
5.0
TIEHANDLE
4.0
BINMODE
4.0
CRAP 2.6
« SingleHandle.pm ↑ Summary Fancy.pm »
1 #!perl
2 package # hide from pause
3 File::Replace::DualHandle;
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/;
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 17 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: called CC=4 SCAR=13.9
22 17 ▶ @_==2 or croak __PACKAGE__."->TIEHANDLE: bad number of args";
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("File::Replace::DualHandle->TIEHANDLE: bad number of args") 16 1 17
23 16 my ($class,$repl) = @_;
24 16 ▶ croak "$class->TIEHANDLE: argument must be a File::Replace object"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($repl) and $repl->isa("File::Replace") 2 14 16
Condition100%3/3
builtin::blessed($repl) and $repl->isa("File::Replace")
!ll&&!rl&&r
1114
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 14 my $self = $class->SUPER::TIEHANDLE($repl->in_fh);
27 14 $self->{repl} = $repl;
28 14 return $self;
29 }
30  
31 4 ▶sub replace { return shift->{repl} }
Subroutine replace: called CC=1 SCAR=0.0
Pod undocumented
32 4 ▶sub in_fh { return shift->{repl}->in_fh }
Subroutine in_fh: called CC=1 SCAR=0.0
Pod undocumented
33 4 ▶sub out_fh { return shift->{repl}->out_fh }
Subroutine out_fh: called CC=1 SCAR=0.0
Pod undocumented
34  
35 8 ▶sub OPEN {
Subroutine OPEN: called CC=5 SCAR=16.1
36 8 my $self = shift;
37 8 ▶ croak "this handle only supports 2- or 3-arg open" unless @_==1||@_==2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 or @_ == 2 2 6 8
Condition100%3/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
332
MC/DC100%2/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table100%3/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
38 6 ▶ croak "layers/filename may not contain an open mode (<, >, etc.)"
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^\s*\+?[<>]/ 2 4 6
39 if $_[0]=~/^\s*\+?[<>]/;
40 4 my $opts = $self->{repl}->options; # old options to copy over
41 4 ▶ $opts->{layers} = @_==2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 2 2 4
42 4 my $filename = shift;
43 # just let the previous $self->{repl} get destroyed here
44 4 $self->{repl} = File::Replace->new($filename, %$opts);
45 4 $self->set_inner_handle($self->{repl}->in_fh);
46 4 return 1;
47 }
48  
49 11 ▶sub CLOSE {
Subroutine CLOSE: called CC=1 SCAR=0.0
50 11 my $self = shift;
51 11 return !!$self->{repl}->finish;
52 }
53  
54 13 ▶sub WRITE {
Subroutine WRITE: called CC=1 SCAR=0.0
55 13 my $self = shift;
56 13 $self->inner_write($self->{repl}->out_fh, @_);
57 }
58  
59 11 ▶sub BINMODE {
Subroutine BINMODE: called CC=4 SCAR=13.9
60 11 my $self = shift;
61 11 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 5 6 11
62 { return binmode($self->{repl}->in_fh, $_[0])
63 5 ▶ && binmode($self->{repl}->out_fh, $_[0]) }
Condition100%3/3
binmode($self->{'repl'}->in_fh, $_[0]) && binmode($self->{'repl'}->out_fh, $_[0])
!ll&&!rl&&r
212
MC/DC100%2/2
binmode($self->{'repl'}->in_fh, $_[0]) && binmode($self->{'repl'}->out_fh, $_[0])
binmode($self->{'repl'}->in_fh, $_[0]) binmode($self->{'repl'}->out_fh, $_[0])
Truth table100%3/3
A && B
A= binmode($self->{'repl'}->in_fh, $_[0])B= binmode($self->{'repl'}->out_fh, $_[0])
ABresult
0X0
100
111
64 else
65 { return binmode($self->{repl}->in_fh)
66 6 ▶ && binmode($self->{repl}->out_fh) }
Condition100%3/3
binmode($self->{'repl'}->in_fh) && binmode($self->{'repl'}->out_fh)
!ll&&!rl&&r
213
MC/DC100%2/2
binmode($self->{'repl'}->in_fh) && binmode($self->{'repl'}->out_fh)
binmode($self->{'repl'}->in_fh) binmode($self->{'repl'}->out_fh)
Truth table100%3/3
A && B
A= binmode($self->{'repl'}->in_fh)B= binmode($self->{'repl'}->out_fh)
ABresult
0X0
100
111
67 }
68 # fileno: "If there is no real file descriptor at the OS level, ... -1 is returned."
69 # since we have two underlying handles, which one the user wants is ambiguous, so just return -1,
70 # this way the check defined(fileno($fh)) for whether the file is open still works
71 2 ▶sub FILENO { return shift->{repl}->is_open ? -1 : undef }
Subroutine FILENO: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'repl'}->is_open ? : 1 1 2
72  
73 1 ▶sub UNTIE {
Subroutine UNTIE: called CC=1 SCAR=0.0
74 1 my $self = shift;
75 1 warnings::warnif("Please don't untie ".ref($self)." handles");
76 1 $self->{repl} = undef;
77 1 $self->SUPER::UNTIE(@_);
78 }
79  
80 14 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
81 14 my $self = shift;
82 # File::Replace destructor will warn on unclosed file
83 14 $self->{repl} = undef;
84 14 $self->SUPER::DESTROY(@_);
85 }
86  
87 2 1;
88 __END__
« SingleHandle.pm ↑ Summary Fancy.pm »