| 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
| |||||||||||||
| 14 | 0 | $path =~ s!\\!/!g; | |||||||||||
| 15 | 0 | $path =~ s!^([a-zA-Z]:|//[^/]+/+[^/]+)!!g; | |||||||||||
| 16 | 0 | ▶ | $path = ($&||'') . canon_path($path); | ||||||||||
|
Condition0%0/2
$& || ''
MC/DC0%0/1
$& || ''
$&
Truth table0%0/2
A
A= $&
| |||||||||||||
| 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
| |||||||||||||
| 25 | 16 | for my $tok (split(/\/+/, $path . '-')) { | |||||||||||
| 26 | 88 | ▶ | next if $tok eq '.'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 72 | ▶ | if ($tok eq '..') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 21 | pop @ret; | |||||||||||
| 29 | 21 | next; | |||||||||||
| 30 | } | ||||||||||||
| 31 | 51 | ▶ | push @ret, $tok if $tok; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | } | ||||||||||||
| 33 | 16 | '/' . substr(join('/', @ret), 0, -1) | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 3 | 1; | |||||||||||
| 37 | __END__ | ||||||||||||