blib/lib/IO/InSitu.pm

filter: Statementstmt 100% 60 / 60 Branchbran 65.0% 13 / 20 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 14 / 14 Podpod 100% 1 / 1 totaltotal 82.7% 91 / 110 CC 14 SCAR 22.2
CC
14
Cov
85%
open_rw
16.9
BEGIN
1.0
BEGIN
1.0
CRAP 9.2
↑ Summary
1 package IO::InSitu;
2  
3 5 ▶use version; $VERSION = qv('0.0.2');
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
10 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 *{caller().'::open_rw'} = \&open_rw;
12 }
13  
14 1 ▶sub _make_tmp {
Subroutine _make_tmp: called CC=1 SCAR=0.0
15 1 my ($in_name) = @_;
16 1 return "$in_name.bak";
17 }
18  
19 3 ▶sub open_rw {
Subroutine open_rw: called CC=14 SCAR=28.3
Pod documented
20 3 ▶ my $opt_arg = ref $_[-1] eq 'HASH' ? pop : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 1 2 3
21  
22 3 my ($in_name, $out_name) = splice @_, 0, 2;
23 3 ▶ $out_name = $in_name if !defined $out_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out_name 0 3 3
24  
25 3 ▶ croak 'Usage: open_rw($in_filename, $opt_out_filename, \%opt_options)'
Branch: 1 branch
BranchTrueFalseTotal
if @_ or not defined $out_name 0 3 3
Condition33%1/3
@_ or not defined $out_name
l!l&&r!l&&!r
003
MC/DC0%0/2
@_ or not defined $out_name
@_ not defined $out_name
Truth table33%1/3
A or not(B)
A= @_B= not defined $out_name
ABresult
1X1
011
000
26 if @_ || !defined $out_name;
27  
28 3 ▶ my $make_tmp = defined $opt_arg->{tmp} ? $opt_arg->{tmp} : \&_make_tmp;
Branch: 1 branch
BranchTrueFalseTotal
defined $opt_arg->{'tmp'} ? : 1 2 3
29  
30 3 ▶ croak "Can't open non-existent input file '$in_name'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $in_name or -e $in_name 0 3 3
Condition33%1/3
ref $in_name or -e $in_name
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $in_name or -e $in_name
ref $in_name -e $in_name
Truth table33%1/3
A or B
A= ref $in_nameB= -e $in_name
ABresult
1X1
011
000
31 if !( ref $in_name || -e $in_name );
32  
33 3 my ($in, $out);
34  
35 3 ▶ if (-e $out_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $out_name) 2 1 3
36 2 my ($in_dev, $in_node) = stat $in_name;
37 2 my ($out_dev, $out_node) = stat $out_name;
38  
39 2 ▶ goto NORMAL_IN if $in_dev != $out_dev || $in_node != $out_node;
Branch: 1 branch
BranchTrueFalseTotal
if $in_dev != $out_dev or $in_node != $out_node 0 2 2
Condition33%1/3
$in_dev != $out_dev or $in_node != $out_node
l!l&&r!l&&!r
002
MC/DC0%0/2
$in_dev != $out_dev or $in_node != $out_node
$in_dev != $out_dev $in_node != $out_node
Truth table33%1/3
A or B
A= $in_dev != $out_devB= $in_node != $out_node
ABresult
1X1
011
000
40  
41 5 ▶ use File::Temp qw( :POSIX );
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 2 my $tmp_name = $make_tmp->($in_name);
44  
45 5 ▶ use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 copy($in_name, $tmp_name);
47  
48 2 ▶ $in = IO::File::SE->new($tmp_name, '<')
Branch: 1 branch
BranchTrueFalseTotal
$in = "IO::File::SE"->new($tmp_name, "<") or croak("Can't open copy of input file '${in_name}'") 2 0 2
49 or croak "Can't open copy of input file '$in_name'";
50  
51 2 goto NORMAL_OUT;
52 }
53  
54 NORMAL_IN:
55 1 ▶ open $in, '<', $in_name
Branch: 1 branch
BranchTrueFalseTotal
open $in, "<", $in_name or croak("Can't open input file '${in_name}': $!") 1 0 1
56 or croak "Can't open input file '$in_name': $!";
57  
58 3 ▶NORMAL_OUT:
Branch: 1 branch
BranchTrueFalseTotal
open $out, ">", $out_name or croak("Can't open output file '${out_name}': $!") 3 0 3
59 open $out, '>', $out_name
60 or croak "Can't open output file '$out_name': $!";
61  
62 3 return ($in, $out);
63 }
64  
65 package IO::File::SE;
66 5 ▶use base qw( IO::File );
Subroutine BEGIN: called CC=1 SCAR=0.0
67 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 5 my %file_name_of;
70  
71 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
72 2 my ($class, $name, @otherargs) = @_;
73 2 my $fh = $class->SUPER::new($name, @otherargs);
74 2 $file_name_of{$fh} = $name;
75 2 return $fh;
76 }
77  
78 2 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
79 2 my ($self) = @_;
80 2 $self->SUPER::DESTROY();
81 2 unlink $file_name_of{$self};
82 2 return;
83 }
84  
85 5 1; # Magic true value required at end of module
86 __END__
↑ Summary