]> git.donarmstrong.com Git - perltidy.git/commitdiff
converted several package vars to lexical vars
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Sep 2020 02:19:26 +0000 (19:19 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Sep 2020 02:19:26 +0000 (19:19 -0700)
lib/Perl/Tidy.pm

index 36dbcfd2d2ed9b4250c91319a27561fa4ffcc330..6623c2dcacb0032c3d1d09c8d52ff120b255ab26 100644 (file)
@@ -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 {