From: Steve Hancock Date: Thu, 10 Sep 2020 02:19:26 +0000 (-0700) Subject: converted several package vars to lexical vars X-Git-Tag: 20200907.01~23 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e9562362b7f6aa10a15b7d6859c4c865d645b431;p=perltidy.git converted several package vars to lexical vars --- diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 36dbcfd2..6623c2dc 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -83,9 +83,6 @@ use vars qw{ $VERSION @ISA @EXPORT - $missing_file_spec - $fh_stderr - $Warn_count }; @ISA = qw( Exporter ); @@ -304,39 +301,44 @@ sub find_input_line_ending { return $ending; } -sub catfile { +{ ## begin closure for sub catfile - # concatenate a path and file basename - # returns undef in case of error - - my @parts = @_; + my $missing_file_spec; BEGIN { eval { require File::Spec }; $missing_file_spec = $@; } - # use File::Spec if we can - unless ($missing_file_spec) { - return File::Spec->catfile(@parts); - } + sub catfile { - # Perl 5.004 systems may not have File::Spec so we'll make - # a simple try. We assume File::Basename is available. - # return if not successful. - my $name = pop @parts; - my $path = join '/', @parts; - my $test_file = $path . $name; - my ( $test_name, $test_path ) = fileparse($test_file); - return $test_file if ( $test_name eq $name ); - return if ( $^O eq 'VMS' ); - - # this should work at least for Windows and Unix: - $test_file = $path . '/' . $name; - ( $test_name, $test_path ) = fileparse($test_file); - return $test_file if ( $test_name eq $name ); - return; -} + # concatenate a path and file basename + # returns undef in case of error + + my @parts = @_; + + # use File::Spec if we can + unless ($missing_file_spec) { + return File::Spec->catfile(@parts); + } + + # Perl 5.004 systems may not have File::Spec so we'll make + # a simple try. We assume File::Basename is available. + # return if not successful. + my $name = pop @parts; + my $path = join '/', @parts; + my $test_file = $path . $name; + my ( $test_name, $test_path ) = fileparse($test_file); + return $test_file if ( $test_name eq $name ); + return if ( $^O eq 'VMS' ); + + # this should work at least for Windows and Unix: + $test_file = $path . '/' . $name; + ( $test_name, $test_path ) = fileparse($test_file); + return $test_file if ( $test_name eq $name ); + return; + } +} ## end closure for sub catfile # Here is a map of the flow of data from the input source to the output # line sink: @@ -373,6 +375,12 @@ sub catfile { # messages. It writes a .LOG file, which may be saved with a # '-log' or a '-g' flag. +{ #<<< + +my $Warn_count; +my $fh_stderr; +sub Warn { my $msg = shift; $fh_stderr->print($msg); $Warn_count++; return } + sub perltidy { my %input_hash = @_; @@ -464,8 +472,6 @@ EOM $fh_stderr = *STDERR; } - sub Warn { my $msg = shift; $fh_stderr->print($msg); $Warn_count++; return } - sub Exit { my $flag = shift; if ($flag) { goto ERROR_EXIT } @@ -1739,7 +1745,8 @@ EOM ERROR_EXIT: return 1; -} # end of main program perltidy +} ## end of main program perltidy +} ## end of closure for sub perltidy sub line_diff {