blib/lib/File/Name/Check.pm

filter: Statementstmt 100% 57 / 57 Branchbran 75.0% 9 / 12 Conditioncond 66.6% 3 / 6 (1 uncoverable) MC/DCmcdc 50.0% 0 / 4 (2 uncoverable) Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 6 totaltotal 86.8% 83 / 99 (3 uncoverable) CC 9 SCAR 7.6
CC
9
Cov
93%
new
4.0
paranoic
3.3
safechars
2.0
CRAP 2.1
↑ Summary
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
BranchTrueFalseTotal
@_ ? : 3 2 5
@_ > 1 ? : 1 2 3
Condition100%2/3
ref $class || $class
l!l&&r!l&&!r
410
MC/DC100%0/2
ref $class || $class
ref $class $class
Truth table100%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($self->safechars($path) and $self->caseunique($path)) 1 0 1
Condition33%1/3
$self->safechars($path) and $self->caseunique($path)
!ll&&!rl&&r
001
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $file =~ /^[0-9a-zA-Z_.-]+$/ 2 0 2
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
BranchTrueFalseTotal
if scalar @files == 1 2 0 2
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
BranchTrueFalseTotal
if ($bytes ne &encode($encoding, scalar &decode($encoding, $bytes))) { } 1 2 3
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__
↑ Summary