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