Permalink
Browse files

add -T (--no-sort) to make example work

  • Loading branch information...
1 parent 4ded649 commit 13059b2530b6e7c00408dc8e1bf45b2c315e0e6f Steven Haryanto committed Sep 30, 2010
Showing with 19 additions and 4 deletions.
  1. +2 −1 bin/perlmv
  2. +7 −2 lib/App/perlmv.pm
  3. +5 −1 t/mv.t
  4. +5 −0 t/testlib.pl
View
@@ -115,7 +115,7 @@ From my real-world usage.
Rename .flv partial files from my Firefox browser cache into ordered names
(part01.flv, part02.flv, and so on):
- $ ls --sort=t -r *01 | xargs perlmv -d -x to-number-ext -e '"part$_.flv"'
+ $ ls --sort=t -r *01 | xargs perlmv -Tdx to-number-ext -e '"part$_.flv"'
DRYRUN: `15D9F85Ad01` -> `01` -> `part01.flv`
DRYRUN: `FF8EB240d01` -> `02` -> `part02.flv`
DRYRUN: `9031E9A8d01` -> `03` -> `part03.flv`
@@ -162,6 +162,7 @@ L<App::perlmv::scriptlets::std>.
-r (--reverse) reverse order of processing (by default order is asciibetically)
-S (--no-symlinks) Do not process symlinks
-s <NAME> (--show) Show source code for scriptlet
+ -T (--no-sort) do not sort files (default is sort ascibetically)
-V (--version) Print version and exit
-v (--verbose) Verbose
-w <NAME> (--write) Write code specified in -e as scriptlet
View
@@ -43,6 +43,7 @@ sub new {
codes => [],
dry_run => 0,
homedir => $homedir,
+ sort_mode => 1, # 1 = sort ascibetically, -1 = reverse, 0 = no sort
overwrite => 0,
process_dir => 1,
process_symlink => 1,
@@ -70,8 +71,9 @@ sub parse_opts {
'o|overwrite' => \$self->{ 'overwrite' },
'p|parents' => \$self->{ 'parents' },
'R|recursive' => \$self->{ 'recursive' },
- 'r|reverse' => \$self->{ 'reverse_order' },
+ 'r|reverse' => sub { $self->{sort_mode} = -1 },
's|show=s' => \$self->{ 'show' },
+ 'T|no-sort' => sub { $self->{sort_mode} = 0 },
'v|verbose' => \$self->{ 'verbose' },
'w|write=s' => \$self->{ 'write' },
'f|files' => sub { $self->{ 'process_dir' } = 0 },
@@ -210,6 +212,7 @@ Options:
-r (--reverse) reverse order of processing (by default order is asciibetically)
-S (--no-symlinks) Do not process symlinks
-s <NAME> (--show) Show source code for scriptlet
+ -T (--no-sort) do not sort files (default is sort ascibetically)
-V (--version) Print version and exit
-v (--verbose) Verbose
-w <NAME> (--write) Write code specified in -e as scriptlet
@@ -348,7 +351,9 @@ sub run_code {
sub _sort {
my $self = shift;
- $self->{reverse_order} ? (reverse sort @_) : (sort @_);
+ $self->{sort_mode} == -1 ? (reverse sort @_) :
+ $self->{sort_mode} == 1 ? (sort @_) :
+ @_;
}
sub process_items {
View
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 2*11;
+use Test::More tests => 2*13;
use FindBin '$Bin';
($Bin) = $Bin =~ /(.+)/;
@@ -25,4 +25,8 @@ test_perlmv([1, 2, 3], {code=>'$_++', reverse_order=>1}, ["2", "3", "4"], 'rever
test_perlmv([qw/aab abb acb/], {codes=>[\'remove-common-prefix', \'remove-common-suffix']}, [qw/a b c/], 'multi (scriptlet+scriptlet)');
test_perlmv([qw/aab abb acb/], {codes=>[\'remove-common-prefix', '"file$_"', \'remove-common-suffix']}, [qw/filea fileb filec/], 'multi (scriptlet+eval+scriptlet)');
+# [2, 3, 1] -> [3.1, 4, 2], but sorted by test_perlmv
+test_perlmv([2, 3, 1], {code=>'$_+1'}, [2.1, 3.1, 4], 'no-sort off');
+test_perlmv([2, 3, 1], {code=>'$_+1', no_sort=>1}, [2, 3.1, 4], 'no-sort on');
+
end_testing();
View
@@ -81,6 +81,7 @@ sub run_perlmv {
when ('parents') { push @cmd, "-p" }
when ('recursive') { push @cmd, "-R" }
when ('reverse_order') { push @cmd, "-r" }
+ when ('no_sort') { push @cmd, "-T" }
when ('verbose') { push @cmd, "-v" }
when ('codes') {
push @cmd, (map {ref($_) ? ("-x", $$_) : ("-e", $_)} @$v);
@@ -102,6 +103,10 @@ sub run_perlmv {
push @{ $pmv->{codes} }, $pmv->load_scriptlet($v);
} elsif ($_ eq 'extra_arg') {
# later, below
+ } elsif ($_ eq 'reverse_order') {
+ $pmv->{sort_mode} = -1;
+ } elsif ($_ eq 'no_sort') {
+ $pmv->{sort_mode} = 0;
} elsif ($_ eq 'code') {
push @{ $pmv->{codes} }, $v;
} else {

0 comments on commit 13059b2

Please sign in to comment.