1 #####################################################################
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')
8 # NOTE: this routine assumes that there aren't any embedded
9 # newlines within any of the array elements. There are no checks
12 #####################################################################
13 package Perl::Tidy::IOScalarArray;
17 our $VERSION = '20220613';
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.
25 return if ( $AUTOLOAD =~ /\bDESTROY$/ );
26 my ( $pkg, $fname, $lno ) = caller();
27 my $my_package = __PACKAGE__;
29 ======================================================================
30 Error detected in package '$my_package', version $VERSION
31 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
32 Called from package: '$pkg'
33 Called from File '$fname' at line '$lno'
34 This error is probably due to a recent programming change
35 ======================================================================
42 # required to avoid call to AUTOLOAD in some versions of perl
46 my ( $package, $rarray, $mode ) = @_;
47 my $ref = ref $rarray;
48 if ( $ref ne 'ARRAY' ) {
50 ------------------------------------------------------------------------
51 expecting ref to ARRAY but got ref to ($ref); trace follows:
52 ------------------------------------------------------------------------
58 return bless [ $rarray, $mode ], $package;
60 elsif ( $mode eq 'r' ) {
62 return bless [ $rarray, $mode, $i_next ], $package;
66 ------------------------------------------------------------------------
67 expecting mode = 'r' or 'w' but got mode ($mode); trace follows:
68 ------------------------------------------------------------------------
75 my $mode = $self->[1];
78 ------------------------------------------------------------------------
79 getline requires mode = 'r' but mode = ($mode); trace follows:
80 ------------------------------------------------------------------------
84 return $self->[0]->[$i];
88 my ( $self, $msg ) = @_;
89 my $mode = $self->[1];
92 ------------------------------------------------------------------------
93 print requires mode = 'w' but mode = ($mode); trace follows:
94 ------------------------------------------------------------------------
97 push @{ $self->[0] }, $msg;