| 1 | package File::Name::Check; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Encode::Locale; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 14 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||
| 15 | # uncoverable condition false | ||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/3
ref $class || $class
MC/DC100%0/2
ref $class || $class
ref $class
$class
Truth table100%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # paranoic = caseunique + safechars | ||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub paranoic { | ||||||||||||||||||||||||||||||
|
Subroutine
paranoic: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 22 | 1 | my $path = shift; | |||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | if ( $self->safechars($path) && $self->caseunique($path) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->safechars($path) and $self->caseunique($path)
MC/DC0%0/2
$self->safechars($path) and $self->caseunique($path)
$self->safechars($path)
$self->caseunique($path)
Truth table33%1/3
A and B
A= $self->safechars($path)B= $self->caseunique($path)
| |||||||||||||||||||||||||||||||||
| 24 | 1 | return 1; | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # matches qr/^[0-9a-zA-Z_.-]+$/ | ||||||||||||||||||||||||||||||||
| 29 | # these chars are also URI-safe | ||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub safechars { | ||||||||||||||||||||||||||||||
|
Subroutine
safechars: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 31 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 32 | 2 | my $path = shift; | |||||||||||||||||||||||||||||||
| 33 | 2 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return 1 if ( $file =~ m/^[0-9a-zA-Z_.-]+$/ ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | # can use locale encoding | ||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub locale { | ||||||||||||||||||||||||||||||
|
Subroutine
locale: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 39 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 40 | 1 | my $path = shift; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 1 | my $encoding = $Encode::Locale::ENCODING_LOCALE_FS; | |||||||||||||||||||||||||||||||
| 43 | 1 | return $self->encoded( $path, $encoding ); | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub encoded { | ||||||||||||||||||||||||||||||
|
Subroutine
encoded: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 47 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 48 | 2 | my $path = shift; | |||||||||||||||||||||||||||||||
| 49 | 2 | my $encoding = shift; | |||||||||||||||||||||||||||||||
| 50 | 2 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 51 | 2 | return $self->_reencode( $file, $encoding ); | |||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # unique under case-insensitive | ||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub caseunique { | ||||||||||||||||||||||||||||||
|
Subroutine
caseunique: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 56 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 57 | 2 | my $path = shift; | |||||||||||||||||||||||||||||||
| 58 | 2 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 59 | 2 | my $dir = File::Spec->catpath( $volume, $directories ); | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 2 | my @files; | |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 2 | opendir(my $dir_handle, $dir); | |||||||||||||||||||||||||||||||
| 64 | 2 | @files = grep{ m/^${file}$/i } readdir($dir_handle); | |||||||||||||||||||||||||||||||
| 65 | 2 | closedir($dir_handle); | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | return 1 if ( scalar @files == 1 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | sub _reencode { | ||||||||||||||||||||||||||||||
|
Subroutine
_reencode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 71 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 72 | 3 | my ( $bytes, $encoding) = @_; | |||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | if ( $bytes ne encode( $encoding, decode( $encoding, $bytes ) ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | # say '*** decoded: ', decode( $encoding, $bytes ); | ||||||||||||||||||||||||||||||||
| 76 | # say ' quoted: ', decode( $encoding, $bytes, Encode::FB_PERLQQ ); | ||||||||||||||||||||||||||||||||
| 77 | 1 | return 0; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | 2 | else { return 1; } | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 2 | 1; | |||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||