| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package File::Name::Check; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
20582
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
116
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
63
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
58
|
use 5.008_005; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
115
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use File::Spec; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
55
|
|
|
10
|
2
|
|
|
2
|
|
982
|
use Encode::Locale; |
|
|
2
|
|
|
|
|
23609
|
|
|
|
2
|
|
|
|
|
100
|
|
|
11
|
2
|
|
|
2
|
|
14
|
use Encode; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1019
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
5
|
|
|
5
|
1
|
1055
|
my $class = shift; |
|
15
|
|
|
|
|
|
|
# uncoverable condition false |
|
16
|
5
|
100
|
66
|
|
|
31
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
|
2
|
100
|
|
|
|
16
|
|
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# paranoic = caseunique + safechars |
|
20
|
|
|
|
|
|
|
sub paranoic { |
|
21
|
5
|
|
|
5
|
1
|
6
|
my $self = shift; |
|
22
|
5
|
|
|
|
|
6
|
my $path = shift; |
|
23
|
|
|
|
|
|
|
|
|
24
|
5
|
|
100
|
|
|
7
|
return ($self->safechars($path) && $self->caseunique($path,@_) ) ; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# matches qr/^[0-9a-zA-Z_.-]+$/ |
|
28
|
|
|
|
|
|
|
# these chars are also URI-safe |
|
29
|
|
|
|
|
|
|
sub safechars { |
|
30
|
7
|
|
|
7
|
1
|
9
|
my $self = shift; |
|
31
|
7
|
|
|
|
|
7
|
my $path = shift; |
|
32
|
7
|
|
|
|
|
80
|
my ( $volume, $directories, $file ) = File::Spec->splitpath($path); |
|
33
|
7
|
|
|
|
|
42
|
return ( $file =~ m/^[0-9a-zA-Z_.-]+$/ ); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# can use locale encoding |
|
37
|
|
|
|
|
|
|
sub locale { |
|
38
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
39
|
1
|
|
|
|
|
1
|
my $path = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
my $encoding = $Encode::Locale::ENCODING_LOCALE_FS; |
|
42
|
1
|
|
|
|
|
3
|
return $self->encoded( $path, $encoding ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub encoded { |
|
46
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
|
47
|
2
|
|
|
|
|
2
|
my $path = shift; |
|
48
|
2
|
|
|
|
|
2
|
my $encoding = shift; |
|
49
|
2
|
|
|
|
|
22
|
my ( $volume, $directories, $file ) = File::Spec->splitpath($path); |
|
50
|
2
|
|
|
|
|
4
|
return $self->_reencode( $file, $encoding ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# unique under case-insensitive |
|
54
|
|
|
|
|
|
|
sub caseunique { |
|
55
|
6
|
|
|
6
|
1
|
6
|
my $self = shift; |
|
56
|
6
|
|
|
|
|
7
|
my $path = shift; |
|
57
|
6
|
|
|
|
|
8
|
my @names = @_; |
|
58
|
|
|
|
|
|
|
|
|
59
|
6
|
|
|
|
|
46
|
my ( $volume, $directories, $file ) = File::Spec->splitpath($path); |
|
60
|
6
|
|
|
|
|
30
|
my $dir = File::Spec->catpath( $volume, $directories ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
6
|
|
|
|
|
5
|
my @files; |
|
63
|
6
|
100
|
|
|
|
23
|
if (@names) { |
|
64
|
4
|
|
|
|
|
14
|
@files = grep{ m/^${file}$/i } @names; |
|
|
8
|
|
|
|
|
35
|
|
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
else { |
|
67
|
2
|
|
|
|
|
75
|
opendir(my $dir_handle, $dir); |
|
68
|
2
|
|
|
|
|
25
|
@files = grep{ m/^${file}$/i } readdir($dir_handle); |
|
|
14
|
|
|
|
|
47
|
|
|
69
|
2
|
|
|
|
|
18
|
closedir($dir_handle); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
6
|
100
|
|
|
|
42
|
return 1 if ( scalar @files == 1 ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _reencode { |
|
76
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
|
77
|
3
|
|
|
|
|
4
|
my ( $bytes, $encoding) = @_; |
|
78
|
2
|
|
|
2
|
|
12
|
no warnings 'utf8'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
181
|
|
|
79
|
3
|
100
|
|
|
|
9
|
if ( $bytes ne encode( $encoding, decode( $encoding, $bytes ) ) ) { |
|
80
|
|
|
|
|
|
|
# say '*** decoded: ', decode( $encoding, $bytes ); |
|
81
|
|
|
|
|
|
|
# say ' quoted: ', decode( $encoding, $bytes, Encode::FB_PERLQQ ); |
|
82
|
1
|
|
|
|
|
77
|
return 0; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
2
|
|
|
|
|
303
|
else { return 1; } |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |