Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Provide $FILE, $DIR, $PARENT

  • Loading branch information...
commit c36679146ebe8064446424f9eea9c52460269105 1 parent 58152b5
Steven Haryanto (on PC) authored
Showing with 38 additions and 7 deletions.
  1. +25 −3 bin/perlmv
  2. +13 −4 lib/App/perlmv.pm
View
28 bin/perlmv
@@ -133,9 +133,31 @@ etc.).
New filename will be taken from the new value of $_ (if it is modified) or the
last expression. So '$_ = lc' and 'lc' are equivalent.
-The arrayref $FILES is also available to the Perl code. It contains,
-unsurprisingly, the list of files to be processed. The Perl code is not supposed
-to modify this value.
+The following variables are also available to the Perl code:
+
+=over 4
+
+=item * C<$FILES> (arrayref)
+
+The list of items to be processed. The Perl code is not supposed to modify this
+value.
+
+=item * C<$FILE> (string)
+
+The filename of item (without path). The Perl code is not supposed to modify
+this value.
+
+=item * C<$DIR> (string)
+
+The directory of item (absolute path). The Perl code is not supposed to modify
+this value.
+
+=item * C<$PARENT> (string)
+
+The name of parent (containing) directory of the item (without path). The Perl
+code is not supposed to modify this value.
+
+=back
Perl code will first be run (eval-ed) once at the beginning for testing, with
C<-TEST> as the filename in C<$_> (and C<$TESTING> will be set to true). Perl
View
17 lib/App/perlmv.pm
@@ -401,19 +401,28 @@ sub process_items {
sub process_item {
my ($self, $code, $code_is_final, $item, $items) = @_;
- $App::perlmv::code::FILES =
+ local $App::perlmv::code::FILES =
[map {ref($_) ? $_->{name_for_script} : $_} @$items];
local $_ = $item->{name_for_script};
- my $old = $item->{real_name};
- $self->run_code($code);
- my $new = $_;
+ my $old = $item->{real_name};
my $aold = abs_path($old);
#die "Invalid path $old" unless defined($aold);
$aold = "" if !defined($aold);
+ my ($oldvol,$olddir,$oldfile)=File::Spec->splitpath($aold);
+ my ($olddirvol,$olddirdir,$olddirfile) = File::Spec->splitpath(
+ abs_path($olddir));
+ local $App::perlmv::code::DIR = $olddir;
+ local $App::perlmv::code::FILE = $oldfile;
+ local $App::perlmv::code::PARENT = $olddirfile;
+
+ $self->run_code($code);
+
+ my $new = $_;
my $anew = abs_path($new);
#die "Invalid path $new" unless defined($anew);
$anew = "" if !defined($anew);
+
$self->{_exists}{$aold}++ if (-e $aold);
return if $aold eq $anew;
Please sign in to comment.
Something went wrong with that request. Please try again.