1 #####################################################################
3 # the Perl::Tidy::LineSource class supplies an object with a 'get_line()' method
4 # which returns the next line to be parsed
6 #####################################################################
8 package Perl::Tidy::LineSource;
11 use English qw( -no_match_vars );
12 our $VERSION = '20230309';
14 use constant DEVEL_MODE => 0;
18 # Catch any undefined sub calls so that we are sure to get
19 # some diagnostic information. This sub should never be called
20 # except for a programming error.
22 return if ( $AUTOLOAD =~ /\bDESTROY$/ );
23 my ( $pkg, $fname, $lno ) = caller();
24 my $my_package = __PACKAGE__;
26 ======================================================================
27 Error detected in package '$my_package', version $VERSION
28 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
29 Called from package: '$pkg'
30 Called from File '$fname' at line '$lno'
31 This error is probably due to a recent programming change
32 ======================================================================
39 # required to avoid call to AUTOLOAD in some versions of perl
44 my ( $class, @args ) = @_;
51 my %args = ( %defaults, @args );
53 my $input_file = $args{input_file};
54 my $rOpts = $args{rOpts};
56 ( my $fh, $input_file ) = Perl::Tidy::streamhandle( $input_file, 'r' );
61 _filename => $input_file,
67 sub close_input_file {
70 # Only close physical files, not STDIN and other objects
71 my $filename = $self->{_filename};
72 if ( $filename ne '-' && !ref $filename ) {
73 my $ok = eval { $self->{_fh}->close(); 1 };
74 if ( !$ok && DEVEL_MODE ) {
75 Fault("Could not close file handle(): $EVAL_ERROR\n");
84 my $fh = $self->{_fh};
85 my $rinput_buffer = $self->{_rinput_buffer};
87 if ( scalar( @{$rinput_buffer} ) ) {
88 $line = shift @{$rinput_buffer};
91 $line = $fh->getline();
93 # patch to read raw mac files under unix, dos
94 # see if the first line has embedded \r's
95 if ( $line && !$self->{_started} ) {
96 if ( $line =~ /[\015][^\015\012]/ ) {
98 # found one -- break the line up and store in a buffer
99 @{$rinput_buffer} = map { $_ . "\n" } split /\015/, $line;
100 my $count = @{$rinput_buffer};
101 $line = shift @{$rinput_buffer};