blib/lib/Path/Canonical.pm

filter: Statementstmt 77.4% 24 / 31 Branchbran 80.0% 8 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 2 totaltotal 71.1% 37 / 52 CC 8 SCAR 17.7
CC
8
Cov
74%
canon_filepath
12.0
canon_path
6.0
BEGIN
1.0
CRAP 5.8
↑ Summary
1 package Path::Canonical;
2 3 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our @EXPORT = qw/canon_path canon_filepath/;
8  
9 3 our $VERSION = "0.05";
10  
11 0 ▶sub canon_filepath {
Subroutine canon_filepath: not called CC=3 SCAR=24.8
Pod undocumented
12 0 my $path = shift;
13 0 ▶ return canon_path($path) if $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" 0 0 0
14 0 $path =~ s!\\!/!g;
15 0 $path =~ s!^([a-zA-Z]:|//[^/]+/+[^/]+)!!g;
16 0 ▶ $path = ($&||'') . canon_path($path);
Condition0%0/2
$& || ''
l!l
00
MC/DC0%0/1
$& || ''
$&
Truth table0%0/2
A
A= $&
Aresult
11
00
17 0 $path =~ s!/!\\!g;
18 0 $path;
19 }
20  
21 16 ▶sub canon_path {
Subroutine canon_path: called CC=6 SCAR=17.9
Pod undocumented
22 16 my $path = shift;
23 16 my @ret = ();
24 16 ▶ $path .= '/' if $path =~ /[.\/]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[[./]$] 9 7 16
25 16 for my $tok (split(/\/+/, $path . '-')) {
26 88 ▶ next if $tok eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $tok eq "." 16 72 88
27 72 ▶ if ($tok eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "..") 21 51 72
28 21 pop @ret;
29 21 next;
30 }
31 51 ▶ push @ret, $tok if $tok;
Branch: 1 branch
BranchTrueFalseTotal
if $tok 41 10 51
32 }
33 16 '/' . substr(join('/', @ret), 0, -1)
34 }
35  
36 3 1;
37 __END__
↑ Summary