line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Rename;
|
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
555255
|
use strict;
|
|
23
|
|
|
|
|
122
|
|
|
23
|
|
|
|
|
678
|
|
4
|
23
|
|
|
23
|
|
113
|
use warnings;
|
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
25782
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter;
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( rename );
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.00_4';
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import {
|
13
|
20
|
|
|
20
|
|
103
|
my $pack = shift;
|
14
|
20
|
|
|
|
|
50
|
my($args, $config) = &_config; # sees @_
|
15
|
20
|
|
|
|
|
1831
|
$pack->export_to_level(1, $pack, @$args);
|
16
|
20
|
|
|
|
|
8406
|
require File::Rename::Options;
|
17
|
20
|
|
|
|
|
182
|
File::Rename::Options->import(@$config);
|
18
|
|
|
|
|
|
|
}
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub rename_files {
|
21
|
45
|
|
|
45
|
1
|
54099
|
my $code = shift;
|
22
|
45
|
|
|
|
|
76
|
my $options = shift;
|
23
|
45
|
|
|
|
|
146
|
_default(\$options);
|
24
|
|
|
|
|
|
|
|
25
|
45
|
|
|
|
|
79
|
my $sub = $code;
|
26
|
45
|
100
|
|
|
|
158
|
if ( $options->{unicode_strings} ) {
|
27
|
3
|
|
|
|
|
1407
|
require File::Rename::Unicode;
|
28
|
|
|
|
|
|
|
$sub = File::Rename::Unicode::code($code,
|
29
|
3
|
|
|
|
|
19
|
$options->{encoding});
|
30
|
|
|
|
|
|
|
}
|
31
|
45
|
|
|
|
|
81
|
my $errors;
|
32
|
45
|
|
|
|
|
123
|
for (@_) {
|
33
|
60
|
|
|
|
|
117
|
my $was = $_;
|
34
|
60
|
100
|
|
|
|
152
|
if ( $options->{filename_only} ) {
|
35
|
9
|
|
|
|
|
52
|
require File::Spec;
|
36
|
9
|
|
|
|
|
123
|
my($vol, $dir, $file) = File::Spec->splitpath($_);
|
37
|
9
|
|
|
|
|
32
|
$sub->() for ($file);
|
38
|
9
|
|
|
|
|
108
|
$_ = File::Spec->catpath($vol, $dir, $file);
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
else {
|
41
|
51
|
|
|
|
|
813
|
$sub->();
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
60
|
100
|
100
|
|
|
2617
|
if( $was eq $_ ){ } # ignore quietly
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
elsif( -e $_ and not $options->{over_write} ) {
|
46
|
2
|
50
|
33
|
|
|
22
|
if (/\s/ or $was =~ /\s/ ) {
|
47
|
0
|
|
|
|
|
0
|
warn "'$was' not renamed: '$_' already exists\n";
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
else {
|
50
|
2
|
|
|
|
|
27
|
warn "$was not renamed: $_ already exists\n";
|
51
|
|
|
|
|
|
|
}
|
52
|
2
|
|
|
|
|
16
|
$errors ++;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
elsif( $options->{no_action} ) {
|
55
|
2
|
|
|
|
|
17
|
print "rename($was, $_)\n";
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
elsif( CORE::rename($was,$_)) {
|
58
|
34
|
100
|
|
|
|
239
|
print "$was renamed as $_\n" if $options->{verbose};
|
59
|
|
|
|
|
|
|
}
|
60
|
1
|
|
|
|
|
21
|
else { warn "Can't rename $was $_: $!\n"; $errors ++; }
|
|
1
|
|
|
|
|
10
|
|
61
|
|
|
|
|
|
|
}
|
62
|
45
|
|
|
|
|
394
|
return !$errors;
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub rename_list {
|
66
|
6
|
|
|
6
|
1
|
39767
|
my($code, $options, $fh, $file) = @_;
|
67
|
6
|
|
|
|
|
71
|
_default(\$options);
|
68
|
|
|
|
|
|
|
print "Reading filenames from ",
|
69
|
|
|
|
|
|
|
( defined $file ? $file
|
70
|
|
|
|
|
|
|
: defined *{$fh}{SCALAR} and
|
71
|
|
|
|
|
|
|
defined ${*{$fh}{SCALAR}} ? ${*{$fh}{SCALAR}}
|
72
|
|
|
|
|
|
|
: "file handle ($fh)"
|
73
|
|
|
|
|
|
|
),
|
74
|
6
|
100
|
33
|
|
|
78
|
"\n" if $options->{verbose};
|
75
|
6
|
|
|
|
|
27
|
my @file;
|
76
|
|
|
|
|
|
|
{
|
77
|
6
|
100
|
|
|
|
17
|
local $/ = "\0" if $options->{input_null};
|
|
6
|
|
|
|
|
40
|
|
78
|
6
|
|
|
|
|
197
|
chop(@file = <$fh>);
|
79
|
|
|
|
|
|
|
}
|
80
|
6
|
|
|
|
|
62
|
rename_files $code, $options, @file;
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub rename {
|
84
|
23
|
|
|
23
|
1
|
7353
|
my($argv, $code, $verbose) = @_;
|
85
|
23
|
100
|
|
|
|
85
|
if( ref $code ) {
|
86
|
19
|
50
|
|
|
|
62
|
if( 'HASH' eq ref $code ) {
|
87
|
19
|
50
|
|
|
|
77
|
if(defined $verbose ) {
|
88
|
0
|
|
|
|
|
0
|
require Carp;
|
89
|
0
|
|
|
|
|
0
|
Carp::carp(<
|
90
|
|
|
|
|
|
|
File::Rename::rename: third argument ($verbose) ignored
|
91
|
|
|
|
|
|
|
CARP
|
92
|
|
|
|
|
|
|
}
|
93
|
19
|
|
|
|
|
52
|
$verbose = $code;
|
94
|
19
|
|
|
|
|
49
|
$code = delete $verbose->{_code};
|
95
|
19
|
50
|
|
|
|
60
|
unless ( $code ) {
|
96
|
0
|
|
|
|
|
0
|
require Carp;
|
97
|
0
|
|
|
|
|
0
|
Carp::carp(<
|
98
|
|
|
|
|
|
|
File::Rename::rename: no _code in $verbose
|
99
|
|
|
|
|
|
|
CARP
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
}
|
104
|
23
|
50
|
|
|
|
73
|
unless( ref $code ) {
|
105
|
23
|
50
|
|
|
|
3144
|
if( my $eval = eval <
|
106
|
|
|
|
|
|
|
sub {
|
107
|
|
|
|
|
|
|
$code
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
CODE
|
110
|
|
|
|
|
|
|
{
|
111
|
23
|
|
|
|
|
76
|
$code = $eval;
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
else {
|
114
|
0
|
|
|
|
|
0
|
my $error = $@;
|
115
|
0
|
|
|
|
|
0
|
$error =~ s/\b(at\s+)\(eval\s+\d+\)\s/$1/g;
|
116
|
0
|
|
|
|
|
0
|
$error =~ s/(\s+line\s+)(\d+)\b/$1 . ($2-1)/eg;
|
|
0
|
|
|
|
|
0
|
|
117
|
0
|
|
|
|
|
0
|
$error =~ s/\.?\s*\z/, in:\n$code\n/;
|
118
|
0
|
|
|
|
|
0
|
die $error;
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
}
|
121
|
23
|
100
|
|
|
|
94
|
if( @$argv ) { rename_files $code, $verbose, @$argv }
|
|
20
|
|
|
|
|
90
|
|
122
|
3
|
|
|
|
|
70
|
else { rename_list $code, $verbose, \*STDIN, 'STDIN' }
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _default {
|
126
|
51
|
|
|
51
|
|
91
|
my $ref = shift;
|
127
|
51
|
100
|
|
|
|
171
|
return if ref $$ref;
|
128
|
12
|
|
|
|
|
22
|
my $verbose = $$ref;
|
129
|
12
|
|
|
|
|
50
|
$$ref = { verbose => $verbose }
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _config {
|
133
|
|
|
|
|
|
|
# copied from GetOpt::Long::import
|
134
|
20
|
|
|
20
|
|
37
|
my @syms = (); # symbols to import
|
135
|
20
|
|
|
|
|
31
|
my @config = (); # configuration
|
136
|
20
|
|
|
|
|
39
|
my $dest = \@syms; # symbols first
|
137
|
20
|
|
|
|
|
54
|
for ( @_ ) {
|
138
|
15
|
100
|
|
|
|
55
|
if ( $_ eq ':config' ) {
|
139
|
7
|
|
|
|
|
14
|
$dest = \@config; # config next
|
140
|
7
|
|
|
|
|
23
|
next;
|
141
|
|
|
|
|
|
|
}
|
142
|
8
|
|
|
|
|
21
|
push(@$dest, $_); # push
|
143
|
|
|
|
|
|
|
}
|
144
|
20
|
|
|
|
|
70
|
return (\@syms, \@config);
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1;
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__
|