| 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 = '20260808'; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 45 | ▶ | use constant DEVEL_MODE => 0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub AUTOLOAD { | ||||||||||||||||||||
| 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; | ||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 29 | 0 | ▶ | return if ( $AUTOLOAD =~ /\bDESTROY$/ ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
Condition0%0/2
$Perl::Tidy::IOScalarArray::AUTOLOAD =~ /\bclose$/ and
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$/
| |||||||||||||||||||||
| 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 | ▶ | 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 | sub new { | ||||||||||||||||||||
| 54 | 0 | ▶ | my ( $package, $rarray, $mode ) = @_; | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 55 | 0 | my $ref = ref($rarray); | |||||||||||||||||||
| 56 | 0 | ▶ | if ( $ref ne 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 | sub getline { | ||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
getline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 83 | 0 | my $mode = $self->[1]; | |||||||||||||||||||
| 84 | 0 | ▶ | if ( $mode ne 'r' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | sub print { | ||||||||||||||||||||
| 96 | 0 | ▶ | my ( $self, $msg ) = @_; | ||||||||||||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 97 | 0 | my $mode = $self->[1]; | |||||||||||||||||||
| 98 | 0 | ▶ | if ( $mode ne 'w' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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; | |||||||||||||||||||