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 our $VERSION = '20200110';
15 my ( $class, $input_file, $rOpts, $rpending_logfile_message ) = @_;
17 my $input_line_ending;
18 if ( $rOpts->{'preserve-line-endings'} ) {
19 $input_line_ending = Perl::Tidy::find_input_line_ending($input_file);
22 ( my $fh, $input_file ) = Perl::Tidy::streamhandle( $input_file, 'r' );
25 # in order to check output syntax when standard output is used,
26 # or when it is an object, we have to make a copy of the file
27 if ( ( $input_file eq '-' || ref $input_file ) && $rOpts->{'check-syntax'} )
30 # Turning off syntax check when input output is used.
31 # The reason is that temporary files cause problems on
33 $rOpts->{'check-syntax'} = 0;
35 ${$rpending_logfile_message} .= <<EOM;
36 Note: --syntax check will be skipped because standard input is used
43 _filename => $input_file,
44 _input_line_ending => $input_line_ending,
50 sub close_input_file {
53 # Only close physical files, not STDIN and other objects
54 my $filename = $self->{_filename};
55 if ( $filename ne '-' && !ref $filename ) {
56 eval { $self->{_fh}->close() };
64 my $fh = $self->{_fh};
65 my $rinput_buffer = $self->{_rinput_buffer};
67 if ( scalar( @{$rinput_buffer} ) ) {
68 $line = shift @{$rinput_buffer};
71 $line = $fh->getline();
73 # patch to read raw mac files under unix, dos
74 # see if the first line has embedded \r's
75 if ( $line && !$self->{_started} ) {
76 if ( $line =~ /[\015][^\015\012]/ ) {
78 # found one -- break the line up and store in a buffer
79 @{$rinput_buffer} = map { $_ . "\n" } split /\015/, $line;
80 my $count = @{$rinput_buffer};
81 $line = shift @{$rinput_buffer};