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