line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Rename;
|
2
|
|
|
|
|
|
|
|
3
|
23
|
|
|
23
|
|
575488
|
use strict;
|
|
23
|
|
|
|
|
120
|
|
|
23
|
|
|
|
|
716
|
|
4
|
23
|
|
|
23
|
|
112
|
use warnings;
|
|
23
|
|
|
|
|
48
|
|
|
23
|
|
|
|
|
26610
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter;
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( rename );
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.01';
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import {
|
13
|
20
|
|
|
20
|
|
108
|
my $pack = shift;
|
14
|
20
|
|
|
|
|
45
|
my($args, $config) = &_config; # sees @_
|
15
|
20
|
|
|
|
|
1850
|
$pack->export_to_level(1, $pack, @$args);
|
16
|
20
|
|
|
|
|
8494
|
require File::Rename::Options;
|
17
|
20
|
|
|
|
|
169
|
File::Rename::Options->import(@$config);
|
18
|
|
|
|
|
|
|
}
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub rename_files {
|
21
|
45
|
|
|
45
|
1
|
50517
|
my $code = shift;
|
22
|
45
|
|
|
|
|
81
|
my $options = shift;
|
23
|
45
|
|
|
|
|
141
|
_default(\$options);
|
24
|
|
|
|
|
|
|
|
25
|
45
|
|
|
|
|
82
|
my $sub = $code;
|
26
|
45
|
100
|
|
|
|
183
|
if ( $options->{unicode_strings} ) {
|
27
|
3
|
|
|
|
|
1377
|
require File::Rename::Unicode;
|
28
|
|
|
|
|
|
|
$sub = File::Rename::Unicode::code($code,
|
29
|
3
|
|
|
|
|
17
|
$options->{encoding});
|
30
|
|
|
|
|
|
|
}
|
31
|
45
|
|
|
|
|
82
|
my $errors;
|
32
|
45
|
|
|
|
|
131
|
for (@_) {
|
33
|
60
|
|
|
|
|
115
|
my $was = $_;
|
34
|
60
|
100
|
|
|
|
146
|
if ( $options->{filename_only} ) {
|
35
|
9
|
|
|
|
|
48
|
require File::Spec;
|
36
|
9
|
|
|
|
|
124
|
my($vol, $dir, $file) = File::Spec->splitpath($_);
|
37
|
9
|
|
|
|
|
33
|
$sub->() for ($file);
|
38
|
9
|
|
|
|
|
131
|
$_ = File::Spec->catpath($vol, $dir, $file);
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
else {
|
41
|
51
|
|
|
|
|
868
|
$sub->();
|
42
|
|
|
|
|
|
|
}
|
43
|
|
|
|
|
|
|
|
44
|
60
|
100
|
100
|
|
|
2684
|
if( $was eq $_ ){ } # ignore quietly
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
elsif( -e $_ and not $options->{over_write} ) {
|
46
|
2
|
50
|
33
|
|
|
21
|
if (/\s/ or $was =~ /\s/ ) {
|
47
|
0
|
|
|
|
|
0
|
warn "'$was' not renamed: '$_' already exists\n";
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
else {
|
50
|
2
|
|
|
|
|
28
|
warn "$was not renamed: $_ already exists\n";
|
51
|
|
|
|
|
|
|
}
|
52
|
2
|
|
|
|
|
17
|
$errors ++;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
elsif( $options->{no_action} ) {
|
55
|
2
|
|
|
|
|
17
|
print "rename($was, $_)\n";
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
elsif( CORE::rename($was,$_)) {
|
58
|
34
|
100
|
|
|
|
269
|
print "$was renamed as $_\n" if $options->{verbose};
|
59
|
|
|
|
|
|
|
}
|
60
|
1
|
|
|
|
|
20
|
else { warn "Can't rename $was $_: $!\n"; $errors ++; }
|
|
1
|
|
|
|
|
8
|
|
61
|
|
|
|
|
|
|
}
|
62
|
45
|
|
|
|
|
431
|
return !$errors;
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub rename_list {
|
66
|
6
|
|
|
6
|
1
|
44717
|
my($code, $options, $fh, $file) = @_;
|
67
|
6
|
|
|
|
|
115
|
_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
|
|
|
69
|
"\n" if $options->{verbose};
|
75
|
6
|
|
|
|
|
35
|
my @file;
|
76
|
|
|
|
|
|
|
{
|
77
|
6
|
100
|
|
|
|
37
|
local $/ = "\0" if $options->{input_null};
|
|
6
|
|
|
|
|
73
|
|
78
|
6
|
|
|
|
|
261
|
chop(@file = <$fh>);
|
79
|
|
|
|
|
|
|
}
|
80
|
6
|
|
|
|
|
141
|
rename_files $code, $options, @file;
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub rename {
|
84
|
23
|
|
|
23
|
1
|
7642
|
my($argv, $code, $verbose) = @_;
|
85
|
23
|
100
|
|
|
|
107
|
if( ref $code ) {
|
86
|
19
|
50
|
|
|
|
82
|
if( 'HASH' eq ref $code ) {
|
87
|
19
|
50
|
|
|
|
59
|
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
|
|
|
|
|
36
|
$verbose = $code;
|
94
|
19
|
|
|
|
|
86
|
$code = delete $verbose->{_code};
|
95
|
19
|
50
|
|
|
|
61
|
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
|
|
|
|
79
|
unless( ref $code ) {
|
105
|
23
|
50
|
|
|
|
3528
|
if( my $eval = eval <
|
106
|
|
|
|
|
|
|
sub {
|
107
|
|
|
|
|
|
|
$code
|
108
|
|
|
|
|
|
|
}
|
109
|
|
|
|
|
|
|
CODE
|
110
|
|
|
|
|
|
|
{
|
111
|
23
|
|
|
|
|
78
|
$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
|
|
|
|
113
|
if( @$argv ) { rename_files $code, $verbose, @$argv }
|
|
20
|
|
|
|
|
78
|
|
122
|
3
|
|
|
|
|
105
|
else { rename_list $code, $verbose, \*STDIN, 'STDIN' }
|
123
|
|
|
|
|
|
|
}
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _default {
|
126
|
51
|
|
|
51
|
|
96
|
my $ref = shift;
|
127
|
51
|
100
|
|
|
|
184
|
return if ref $$ref;
|
128
|
12
|
|
|
|
|
22
|
my $verbose = $$ref;
|
129
|
12
|
|
|
|
|
65
|
$$ref = { verbose => $verbose }
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _config {
|
133
|
|
|
|
|
|
|
# copied from GetOpt::Long::import
|
134
|
20
|
|
|
20
|
|
46
|
my @syms = (); # symbols to import
|
135
|
20
|
|
|
|
|
30
|
my @config = (); # configuration
|
136
|
20
|
|
|
|
|
40
|
my $dest = \@syms; # symbols first
|
137
|
20
|
|
|
|
|
63
|
for ( @_ ) {
|
138
|
15
|
100
|
|
|
|
43
|
if ( $_ eq ':config' ) {
|
139
|
7
|
|
|
|
|
12
|
$dest = \@config; # config next
|
140
|
7
|
|
|
|
|
19
|
next;
|
141
|
|
|
|
|
|
|
}
|
142
|
8
|
|
|
|
|
21
|
push(@$dest, $_); # push
|
143
|
|
|
|
|
|
|
}
|
144
|
20
|
|
|
|
|
64
|
return (\@syms, \@config);
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1;
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__
|