Tidy/IOScalarArray.pm

filter: Statementstmt 30.4% 14 / 46 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 3 totaltotal 24.0% 18 / 75 CC 9 SCAR 24.1
CC
9
Cov
23%
AUTOLOAD
20.0
new
20.0
getline
6.0
CRAP 11.1
« Tidy/Diagnostics.pm ↑ Summary Tidy/IOScalar.pm »
1 package Perl::Tidy::IOScalarArray;
2  
3 #####################################################################
4 #
5 # This is a stripped down version of IO::ScalarArray
6 # Given a reference to an array, it supplies either:
7 # a getline method which reads lines (mode='r'), or
8 # a print method which reads lines (mode='w')
9 #
10 # NOTE: this routine assumes that there aren't any embedded
11 # newlines within any of the array elements. There are no checks
12 # for that.
13 #
14 #####################################################################
15  
16 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 45 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 45 our $VERSION = '20260826';
20  
21 45 ▶use constant DEVEL_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
24  
25 # Catch any undefined sub calls so that we are sure to get
26 # some diagnostic information. This sub should never be called
27 # except for a programming error.
28 0 our $AUTOLOAD;
29 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
30  
31 # Originally there was a dummy sub close. All calls to it should have been
32 # eliminated, but for safety we will check for them here.
33 0 ▶ return 1 if ( $AUTOLOAD =~ /\bclose$/ && !DEVEL_MODE );
Branch: 1 branch
BranchTrueFalseTotal
if 0 0 0
Condition0%0/2
$Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bclose$/ and
!ll
00
MC/DC0%0/1
$Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bclose$/ and
$Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bclose$/
Truth table0%0/2
A
A= $Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bclose$/
Aresult
00
11
34 0 my ( $pkg, $fname, $lno ) = caller();
35 0 my $my_package = __PACKAGE__;
36 0 print {*STDERR} <<EOM;
37 ======================================================================
38 Error detected in package '$my_package', version $VERSION
39 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
40 Called from package: '$pkg'
41 Called from File '$fname' at line '$lno'
42 This error is probably due to a recent programming change
43 ======================================================================
44 EOM
45 0 exit 1;
46 } ## end sub AUTOLOAD
47  
48 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
49  
50 # required to avoid call to AUTOLOAD in some versions of perl
51 }
52  
53 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my ( $package, $rarray, $mode ) = @_;
55 0 my $ref = ref($rarray);
56 0 ▶ if ( $ref ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref ne "ARRAY") 0 0 0
57 0 confess <<EOM;
58 ------------------------------------------------------------------------
59 expecting ref to ARRAY but got ref to ($ref); trace follows:
60 ------------------------------------------------------------------------
61 EOM
62  
63 }
64 0 ▶ if ( $mode eq 'w' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'w') { } 0 0 0
elsif ($mode eq 'r') { } 0 0 0
65 0 @{$rarray} = ();
66 0 return bless [ $rarray, $mode ], $package;
67 }
68 elsif ( $mode eq 'r' ) {
69 0 my $i_next = 0;
70 0 return bless [ $rarray, $mode, $i_next ], $package;
71 }
72 else {
73 0 confess <<EOM;
74 ------------------------------------------------------------------------
75 expecting mode = 'r' or 'w' but got mode ($mode); trace follows:
76 ------------------------------------------------------------------------
77 EOM
78 }
79 } ## end sub new
80  
81 0 ▶sub getline {
Subroutine getline: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my $self = shift;
83 0 my $mode = $self->[1];
84 0 ▶ if ( $mode ne 'r' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode ne "r") 0 0 0
85 0 confess <<EOM;
86 ------------------------------------------------------------------------
87 getline requires mode = 'r' but mode = ($mode); trace follows:
88 ------------------------------------------------------------------------
89 EOM
90 }
91 0 my $i = $self->[2]++;
92 0 return $self->[0]->[$i];
93 } ## end sub getline
94  
95 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my ( $self, $msg ) = @_;
97 0 my $mode = $self->[1];
98 0 ▶ if ( $mode ne 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode ne "w") 0 0 0
99 0 confess <<EOM;
100 ------------------------------------------------------------------------
101 print requires mode = 'w' but mode = ($mode); trace follows:
102 ------------------------------------------------------------------------
103 EOM
104 }
105 0 push @{ $self->[0] }, $msg;
106 0 return;
107 } ## end sub print
108 45 1;
« Tidy/Diagnostics.pm ↑ Summary Tidy/IOScalar.pm »