| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ##################################################################### | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | # This is a stripped down version of IO::ScalarArray | 
| 4 |  |  |  |  |  |  | # Given a reference to an array, it supplies either: | 
| 5 |  |  |  |  |  |  | # a getline method which reads lines (mode='r'), or | 
| 6 |  |  |  |  |  |  | # a print method which reads lines (mode='w') | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | # NOTE: this routine assumes that there aren't any embedded | 
| 9 |  |  |  |  |  |  | # newlines within any of the array elements.  There are no checks | 
| 10 |  |  |  |  |  |  | # for that. | 
| 11 |  |  |  |  |  |  | # | 
| 12 |  |  |  |  |  |  | ##################################################################### | 
| 13 |  |  |  |  |  |  | package Perl::Tidy::IOScalarArray; | 
| 14 | 39 |  |  | 39 |  | 318 | use strict; | 
|  | 39 |  |  |  |  | 84 |  | 
|  | 39 |  |  |  |  | 1269 |  | 
| 15 | 39 |  |  | 39 |  | 272 | use warnings; | 
|  | 39 |  |  |  |  | 159 |  | 
|  | 39 |  |  |  |  | 989 |  | 
| 16 | 39 |  |  | 39 |  | 275 | use Carp; | 
|  | 39 |  |  |  |  | 145 |  | 
|  | 39 |  |  |  |  | 3478 |  | 
| 17 |  |  |  |  |  |  | our $VERSION = '20230909'; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 39 |  |  | 39 |  | 395 | use constant DEVEL_MODE => 0; | 
|  | 39 |  |  |  |  | 139 |  | 
|  | 39 |  |  |  |  | 22451 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | # Catch any undefined sub calls so that we are sure to get | 
| 24 |  |  |  |  |  |  | # some diagnostic information.  This sub should never be called | 
| 25 |  |  |  |  |  |  | # except for a programming error. | 
| 26 | 0 |  |  | 0 |  |  | our $AUTOLOAD; | 
| 27 | 0 | 0 |  |  |  |  | return if ( $AUTOLOAD =~ /\bDESTROY$/ ); | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # Originally there was a dummy sub close. All calls to it should have been | 
| 30 |  |  |  |  |  |  | # eliminated, but for safety we will check for them here. | 
| 31 | 0 | 0 | 0 |  |  |  | return 1 if ( $AUTOLOAD =~ /\bclose$/ && !DEVEL_MODE ); | 
| 32 | 0 |  |  |  |  |  | my ( $pkg, $fname, $lno ) = caller(); | 
| 33 | 0 |  |  |  |  |  | my $my_package = __PACKAGE__; | 
| 34 | 0 |  |  |  |  |  | print {*STDERR} <<EOM; | 
|  | 0 |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | ====================================================================== | 
| 36 |  |  |  |  |  |  | Error detected in package '$my_package', version $VERSION | 
| 37 |  |  |  |  |  |  | Received unexpected AUTOLOAD call for sub '$AUTOLOAD' | 
| 38 |  |  |  |  |  |  | Called from package: '$pkg' | 
| 39 |  |  |  |  |  |  | Called from File '$fname'  at line '$lno' | 
| 40 |  |  |  |  |  |  | This error is probably due to a recent programming change | 
| 41 |  |  |  |  |  |  | ====================================================================== | 
| 42 |  |  |  |  |  |  | EOM | 
| 43 | 0 |  |  |  |  |  | exit 1; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  | 0 |  |  | sub DESTROY { | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | # required to avoid call to AUTOLOAD in some versions of perl | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub new { | 
| 52 | 0 |  |  | 0 | 0 |  | my ( $package, $rarray, $mode ) = @_; | 
| 53 | 0 |  |  |  |  |  | my $ref = ref $rarray; | 
| 54 | 0 | 0 |  |  |  |  | if ( $ref ne 'ARRAY' ) { | 
| 55 | 0 |  |  |  |  |  | confess <<EOM; | 
| 56 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 57 |  |  |  |  |  |  | expecting ref to ARRAY but got ref to ($ref); trace follows: | 
| 58 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 59 |  |  |  |  |  |  | EOM | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | } | 
| 62 | 0 | 0 |  |  |  |  | if ( $mode eq 'w' ) { | 
|  |  | 0 |  |  |  |  |  | 
| 63 | 0 |  |  |  |  |  | @{$rarray} = (); | 
|  | 0 |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | return bless [ $rarray, $mode ], $package; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | elsif ( $mode eq 'r' ) { | 
| 67 | 0 |  |  |  |  |  | my $i_next = 0; | 
| 68 | 0 |  |  |  |  |  | return bless [ $rarray, $mode, $i_next ], $package; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | else { | 
| 71 | 0 |  |  |  |  |  | confess <<EOM; | 
| 72 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 73 |  |  |  |  |  |  | expecting mode = 'r' or 'w' but got mode ($mode); trace follows: | 
| 74 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 75 |  |  |  |  |  |  | EOM | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub getline { | 
| 80 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 81 | 0 |  |  |  |  |  | my $mode = $self->[1]; | 
| 82 | 0 | 0 |  |  |  |  | if ( $mode ne 'r' ) { | 
| 83 | 0 |  |  |  |  |  | confess <<EOM; | 
| 84 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 85 |  |  |  |  |  |  | getline requires mode = 'r' but mode = ($mode); trace follows: | 
| 86 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 87 |  |  |  |  |  |  | EOM | 
| 88 |  |  |  |  |  |  | } | 
| 89 | 0 |  |  |  |  |  | my $i = $self->[2]++; | 
| 90 | 0 |  |  |  |  |  | return $self->[0]->[$i]; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub print    ## no critic (Subroutines::ProhibitBuiltinHomonyms) | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 0 |  |  | 0 | 0 |  | my ( $self, $msg ) = @_; | 
| 96 | 0 |  |  |  |  |  | my $mode = $self->[1]; | 
| 97 | 0 | 0 |  |  |  |  | if ( $mode ne 'w' ) { | 
| 98 | 0 |  |  |  |  |  | confess <<EOM; | 
| 99 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 100 |  |  |  |  |  |  | print requires mode = 'w' but mode = ($mode); trace follows: | 
| 101 |  |  |  |  |  |  | ------------------------------------------------------------------------ | 
| 102 |  |  |  |  |  |  | EOM | 
| 103 |  |  |  |  |  |  | } | 
| 104 | 0 |  |  |  |  |  | push @{ $self->[0] }, $msg; | 
|  | 0 |  |  |  |  |  |  | 
| 105 | 0 |  |  |  |  |  | return; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  | 1; |