| 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.09'; | |||||||||||||||||||||||||||||||
| 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
documented
| |||||||||||||||||||||||||||||||||
| 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 | 5 | ▶ | sub paranoic { | ||||||||||||||||||||||||||||||
|
Subroutine
paranoic: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 22 | 5 | my $path = shift; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | return ($self->safechars($path) && $self->caseunique($path,@_) ) ; | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->safechars($path) && $self->caseunique($path, @_)
MC/DC100%2/2
$self->safechars($path) && $self->caseunique($path, @_)
$self->safechars($path)
$self->caseunique($path, @_)
Truth table100%3/3
A && B
A= $self->safechars($path)B= $self->caseunique($path, @_)
| |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # matches qr/^[0-9a-zA-Z_.-]+$/ | ||||||||||||||||||||||||||||||||
| 28 | # these chars are also URI-safe | ||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | sub safechars { | ||||||||||||||||||||||||||||||
|
Subroutine
safechars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||
| 31 | 7 | my $path = shift; | |||||||||||||||||||||||||||||||
| 32 | 7 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 33 | 7 | return ( $file =~ m/^[0-9a-zA-Z_.-]+$/ ); | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | # can use locale encoding | ||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub locale { | ||||||||||||||||||||||||||||||
|
Subroutine
locale: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 38 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 39 | 1 | my $path = shift; | |||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 1 | my $encoding = $Encode::Locale::ENCODING_LOCALE_FS; | |||||||||||||||||||||||||||||||
| 42 | 1 | return $self->encoded( $path, $encoding ); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub encoded { | ||||||||||||||||||||||||||||||
|
Subroutine
encoded: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 46 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 47 | 2 | my $path = shift; | |||||||||||||||||||||||||||||||
| 48 | 2 | my $encoding = shift; | |||||||||||||||||||||||||||||||
| 49 | 2 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 50 | 2 | return $self->_reencode( $file, $encoding ); | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | # unique under case-insensitive | ||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub caseunique { | ||||||||||||||||||||||||||||||
|
Subroutine
caseunique: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 55 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||
| 56 | 6 | my $path = shift; | |||||||||||||||||||||||||||||||
| 57 | 6 | my @names = @_; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 6 | my ( $volume, $directories, $file ) = File::Spec->splitpath($path); | |||||||||||||||||||||||||||||||
| 60 | 6 | my $dir = File::Spec->catpath( $volume, $directories ); | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 6 | my @files; | |||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | if (@names) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 4 | @files = grep{ m/^${file}$/i } @names; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||
| 67 | 2 | opendir(my $dir_handle, $dir); | |||||||||||||||||||||||||||||||
| 68 | 2 | @files = grep{ m/^${file}$/i } readdir($dir_handle); | |||||||||||||||||||||||||||||||
| 69 | 2 | closedir($dir_handle); | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | return 1 if ( scalar @files == 1 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | sub _reencode { | ||||||||||||||||||||||||||||||
|
Subroutine
_reencode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 76 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 77 | 3 | my ( $bytes, $encoding) = @_; | |||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 79 | 3 | ▶ | if ( $bytes ne encode( $encoding, decode( $encoding, $bytes ) ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | # say '*** decoded: ', decode( $encoding, $bytes ); | ||||||||||||||||||||||||||||||||
| 81 | # say ' quoted: ', decode( $encoding, $bytes, Encode::FB_PERLQQ ); | ||||||||||||||||||||||||||||||||
| 82 | 1 | return 0; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | 2 | else { return 1; } | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||||||