package Perl::Tidy::LineSource;
use strict;
use warnings;
-our $VERSION = '20200110';
+use English qw( -no_match_vars );
+our $VERSION = '20230309';
+
+use constant DEVEL_MODE => 0;
+
+sub AUTOLOAD {
+
+ # Catch any undefined sub calls so that we are sure to get
+ # some diagnostic information. This sub should never be called
+ # except for a programming error.
+ our $AUTOLOAD;
+ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
+ my ( $pkg, $fname, $lno ) = caller();
+ my $my_package = __PACKAGE__;
+ print STDERR <<EOM;
+======================================================================
+Error detected in package '$my_package', version $VERSION
+Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
+Called from package: '$pkg'
+Called from File '$fname' at line '$lno'
+This error is probably due to a recent programming change
+======================================================================
+EOM
+ exit 1;
+}
-sub new {
+sub DESTROY {
- my ( $class, $input_file, $rOpts, $rpending_logfile_message ) = @_;
+ # required to avoid call to AUTOLOAD in some versions of perl
+}
- my $input_line_ending;
- if ( $rOpts->{'preserve-line-endings'} ) {
- $input_line_ending = Perl::Tidy::find_input_line_ending($input_file);
- }
+sub new {
- ( my $fh, $input_file ) = Perl::Tidy::streamhandle( $input_file, 'r' );
- return unless $fh;
+ my ( $class, @args ) = @_;
- # in order to check output syntax when standard output is used,
- # or when it is an object, we have to make a copy of the file
- if ( ( $input_file eq '-' || ref $input_file ) && $rOpts->{'check-syntax'} )
- {
+ my %defaults = (
+ input_file => undef,
+ rOpts => undef,
+ );
- # Turning off syntax check when input output is used.
- # The reason is that temporary files cause problems on
- # on many systems.
- $rOpts->{'check-syntax'} = 0;
+ my %args = ( %defaults, @args );
- ${$rpending_logfile_message} .= <<EOM;
-Note: --syntax check will be skipped because standard input is used
-EOM
+ my $input_file = $args{input_file};
+ my $rOpts = $args{rOpts};
- }
+ ( my $fh, $input_file ) = Perl::Tidy::streamhandle( $input_file, 'r' );
+ return unless $fh;
return bless {
- _fh => $fh,
- _filename => $input_file,
- _input_line_ending => $input_line_ending,
- _rinput_buffer => [],
- _started => 0,
+ _fh => $fh,
+ _filename => $input_file,
+ _rinput_buffer => [],
+ _started => 0,
}, $class;
}
# Only close physical files, not STDIN and other objects
my $filename = $self->{_filename};
if ( $filename ne '-' && !ref $filename ) {
- eval { $self->{_fh}->close() };
+ my $ok = eval { $self->{_fh}->close(); 1 };
+ if ( !$ok && DEVEL_MODE ) {
+ Fault("Could not close file handle(): $EVAL_ERROR\n");
+ }
}
return;
}
return $line;
}
1;
-