lib/Badger/Filesystem/Universal.pm

filter: Statementstmt 20.0% 10 / 50 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 27.2% 3 / 11 Podpod n/a totaltotal 11.5% 13 / 113 CC 21 SCAR 44.4
CC
21
Cov
11%
catpath
182.0
canonpath
30.0
splitpath
20.0
CRAP 84.5
« lib/Badger/Reporter.pm ↑ Summary blib/lib/Badger/Modules.pm »
1 #========================================================================
2 #
3 # Badger::Filesystem::Universal
4 #
5 # DESCRIPTION
6 # Subclass of Badger::Filesystem which implements a universal
7 # filesystem for representing URIs. It always uses forward slashes
8 # as path separators regardless of the local filesystem convention.
9 #
10 # AUTHOR
11 # Andy Wardley <abw@wardley.org>
12 #
13 #========================================================================
14  
15 package Badger::Filesystem::Universal;
16  
17 1 ▶use Badger::Debug ':dump';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 use Badger::Class
19 1 version => 0.01,
20 debug => 0,
21 base => 'Badger::Filesystem',
22 constants => 'HASH',
23 constant => {
24 UFS => __PACKAGE__,
25 ROOTDIR => '/',
26 CURDIR => '.',
27 UPDIR => '..',
28 FILESPEC => 'Badger::Filesystem::FileSpec::Universal',
29 spec => 'Badger::Filesystem::FileSpec::Universal',
30 },
31 exports => {
32 any => 'UFS',
33 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35  
36 #-----------------------------------------------------------------------
37 # Replacement for File::Spec implementing that various methods that the
38 # filesystem needs to construct paths.
39 #-----------------------------------------------------------------------
40  
41 package Badger::Filesystem::FileSpec::Universal;
42  
43 use Badger::Class
44 1 version => 0.01,
45 debug => 0,
46 base => 'Badger::Base',
47 constant => {
48 SLASH => '/',
49 SLASHRX => qr{/},
50 COLON => ':',
51 rootdir => '/',
52 curdir => '.',
53 updir => '..',
54 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56  
57 sub catdir {
58 0 ▶ my $self = shift;
Subroutine catdir: not called CC=1 SCAR=6.9
59 0 join(SLASH, @_);
60 }
61  
62 sub catpath {
63 0 ▶ my ($self, $volume, $dir, $file) = @_;
Subroutine catpath: not called CC=13 SCAR=52.0
64 0 my $path = '';
65  
66 # yuk
67 0 ▶ $volume = undef unless defined $volume and length $volume;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $volume and length $volume 0 0 0
Condition0%0/3
defined $volume and length $volume
!ll&&!rl&&r
000
MC/DC0%0/2
defined $volume and length $volume
defined $volume length $volume
Truth table0%0/3
A and B
A= defined $volumeB= length $volume
ABresult
0X0
100
111
68 0 ▶ $dir = undef unless defined $dir and length $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and length $dir 0 0 0
Condition0%0/3
defined $dir and length $dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dir and length $dir
defined $dir length $dir
Truth table0%0/3
A and B
A= defined $dirB= length $dir
ABresult
0X0
100
111
69 0 ▶ $file = undef unless defined $file and length $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and length $file 0 0 0
Condition0%0/3
defined $file and length $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and length $file
defined $file length $file
Truth table0%0/3
A and B
A= defined $fileB= length $file
ABresult
0X0
100
111
70
71 0 ▶ $path .= $volume.COLON if defined $volume;
Branch: 1 branch
BranchTrueFalseTotal
if defined $volume 0 0 0
72 0 ▶ $path .= SLASH if defined $volume and defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $volume and defined $dir 0 0 0
Condition0%0/3
defined $volume and defined $dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $volume and defined $dir
defined $volume defined $dir
Truth table0%0/3
A and B
A= defined $volumeB= defined $dir
ABresult
0X0
100
111
73 0 ▶ $path .= $dir.SLASH if defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dir 0 0 0
74 0 ▶ $path .= $file if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 0 0 0
75 0 ▶ $self->debug("catpath() [$volume] [$dir] [$file] => [$path]") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Badger::Filesystem::FileSpec::Universal::DEBUG 0 0 0
76 0 return $path;
77 }
78  
79 sub splitpath {
80 0 ▶ my ($self, $path) = @_;
Subroutine splitpath: not called CC=4 SCAR=30.0
81 0 my ($volume, $dir, $file);
82 0 $dir = $path;
83 0 ▶ $volume = $1 if $dir =~ s/^(\w+)://;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ s/^(\w+):// 0 0 0
84 0 ▶ $file = $1 if $dir =~ s/([^\/]+)$//;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ s[([^/]+)$][] 0 0 0
85 0 $dir =~ s{(?<=.)/$}{};
86 0 $dir =~ s{//}{/}g;
87 0 ▶ $self->debug("splitpath() [$path] => [$volume] [$dir] [$file]") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Badger::Filesystem::FileSpec::Universal::DEBUG 0 0 0
88 0 return ($volume, $dir, $file);
89 }
90  
91 sub splitdir {
92 0 ▶ my ($self, $dir) = @_;
Subroutine splitdir: not called CC=2 SCAR=17.9
93 0 ▶ $self->debug("splitdir($dir) => [", join('] [', split(SLASHRX, $dir)), ']') if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Badger::Filesystem::FileSpec::Universal::DEBUG 0 0 0
94 0 return split(SLASHRX, $dir);
95 }
96  
97 sub file_name_is_absolute {
98 0 ▶ my ($self, $path) = @_;
Subroutine file_name_is_absolute: not called CC=1 SCAR=6.9
99 0 $self->debug("testing $path");
100 0 return $path =~ m{^/};
101 }
102  
103 sub canonpath {
104 0 ▶ my $self = shift;
Subroutine canonpath: not called CC=5 SCAR=34.0
105 0 my ($volume, $dir, $name) = $self->splitpath(@_);
106 0 my @dirs = $self->splitdir($dir);
107 0 my ($node, @path);
108 0 ▶ while (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) 0 0 0
109 0 $node = shift @dirs;
110 0 ▶ if ($node eq curdir) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node eq '.') { } 0 0 0
elsif ($node eq '..') { } 0 0 0
111 # do nothing
112 }
113 elsif ($node eq updir) {
114 0 ▶ pop @path if @path;
Branch: 1 branch
BranchTrueFalseTotal
if @path 0 0 0
115 }
116 else {
117 0 push(@path, $node);
118 }
119 }
120 0 return $self->catpath(
121 $volume,
122 $self->catdir(@path),
123 $name
124 );
125 }
126  
127 sub abs2rel {
128 0 ▶ shift->todo;
Subroutine abs2rel: not called CC=1 SCAR=6.9
129 }
130  
131 sub no_upwards {
132 0 ▶ shift->todo;
Subroutine no_upwards: not called CC=1 SCAR=6.9
133 }
134  
135 1 1;
136  
« lib/Badger/Reporter.pm ↑ Summary blib/lib/Badger/Modules.pm »