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 = '20221112';
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 $input_line_ending;
57 if ( $rOpts->{'preserve-line-endings'} ) {
58 $input_line_ending = Perl::Tidy::find_input_line_ending($input_file);
61 ( my $fh, $input_file ) = Perl::Tidy::streamhandle( $input_file, 'r' );
66 _filename => $input_file,
67 _input_line_ending => $input_line_ending,
73 sub close_input_file {
76 # Only close physical files, not STDIN and other objects
77 my $filename = $self->{_filename};
78 if ( $filename ne '-' && !ref $filename ) {
79 my $ok = eval { $self->{_fh}->close(); 1 };
80 if ( !$ok && DEVEL_MODE ) {
81 Fault("Could not close file handle(): $EVAL_ERROR\n");
90 my $fh = $self->{_fh};
91 my $rinput_buffer = $self->{_rinput_buffer};
93 if ( scalar( @{$rinput_buffer} ) ) {
94 $line = shift @{$rinput_buffer};
97 $line = $fh->getline();
99 # patch to read raw mac files under unix, dos
100 # see if the first line has embedded \r's
101 if ( $line && !$self->{_started} ) {
102 if ( $line =~ /[\015][^\015\012]/ ) {
104 # found one -- break the line up and store in a buffer
105 @{$rinput_buffer} = map { $_ . "\n" } split /\015/, $line;
106 my $count = @{$rinput_buffer};
107 $line = shift @{$rinput_buffer};