| 1 | package Path::Trim; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use version; our $VERSION = qv('0.0.3'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 1 | return bless {}, __PACKAGE__; | |||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 130 | ▶ | sub get_current_directory { | ||||||||||||||||||||||||||
|
Subroutine
get_current_directory: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 130 | my $self = shift; | |||||||||||||||||||||||||||
| 14 | 130 | ▶ | return $self->{'current_directory'} || '.'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'current_directory'} || '.'
MC/DC100%1/1
$self->{'current_directory'} || '.'
$self->{'current_directory'}
Truth table100%2/2
A
A= $self->{'current_directory'}
| |||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub set_current_directory { | ||||||||||||||||||||||||||
|
Subroutine
set_current_directory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 2 | my ( $self, $current_directory ) = @_; | |||||||||||||||||||||||||||
| 19 | 2 | return $self->{'current_directory'} = $current_directory; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 130 | ▶ | sub get_parent_directory { | ||||||||||||||||||||||||||
|
Subroutine
get_parent_directory: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 130 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 130 | ▶ | return $self->{'parent_directory'} || '..'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'parent_directory'} || '..'
MC/DC100%1/1
$self->{'parent_directory'} || '..'
$self->{'parent_directory'}
Truth table100%2/2
A
A= $self->{'parent_directory'}
| |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | sub set_parent_directory { | ||||||||||||||||||||||||||
|
Subroutine
set_parent_directory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 2 | my ( $self, $parent_directory ) = @_; | |||||||||||||||||||||||||||
| 29 | 2 | return $self->{'parent_directory'} = $parent_directory; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 128 | ▶ | sub get_directory_separator { | ||||||||||||||||||||||||||
|
Subroutine
get_directory_separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 128 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 128 | return $self->{'directory_separator'}; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub set_directory_separator { | ||||||||||||||||||||||||||
|
Subroutine
set_directory_separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 2 | my ( $self, $directory_separator ) = @_; | |||||||||||||||||||||||||||
| 39 | 2 | return $self->{'directory_separator'} = $directory_separator; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 128 | ▶ | sub trim_path { | ||||||||||||||||||||||||||
|
Subroutine
trim_path: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 128 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 44 | 128 | my $current_directory = $self->get_current_directory(); | |||||||||||||||||||||||||||
| 45 | 128 | my $parent_directory = $self->get_parent_directory(); | |||||||||||||||||||||||||||
| 46 | 128 | my $directory_separator = $self->get_directory_separator(); | |||||||||||||||||||||||||||
| 47 | 128 | my ( $left_stripped, $right_stripped ); | |||||||||||||||||||||||||||
| 48 | 128 | ▶ | if ( $path =~ s/^\Q$directory_separator\E// ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 64 | $left_stripped = 1; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 128 | ▶ | if ( $path =~ s/\Q$directory_separator\E$// ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 64 | $right_stripped = 1; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 128 | my @dirs = split /\Q$directory_separator\E/, $path; | |||||||||||||||||||||||||||
| 55 | 128 | my @new_path; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 128 | for my $dir (@dirs) { | |||||||||||||||||||||||||||
| 58 | 400 | ▶ | if ( $dir eq $parent_directory ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | 160 | ▶ | if ( @new_path && $new_path[-1] ne $parent_directory ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@new_path and $new_path[-1] ne $parent_directory
MC/DC100%2/2
@new_path and $new_path[-1] ne $parent_directory
@new_path
$new_path[-1] ne $parent_directory
Truth table100%3/3
A and B
A= @new_pathB= $new_path[-1] ne $parent_directory
| |||||||||||||||||||||||||||||
| 60 | 40 | pop @new_path; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 120 | push @new_path, $parent_directory; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | elsif ( $dir ne $current_directory ) { | ||||||||||||||||||||||||||||
| 67 | 112 | push @new_path, $dir; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 128 | ▶ | if ( !@new_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 16 | push @new_path, $current_directory; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 128 | my $new_path = join $directory_separator, @new_path; | |||||||||||||||||||||||||||
| 76 | 128 | ▶ | if ($left_stripped) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 64 | $new_path = $directory_separator . $new_path; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 128 | ▶ | if ($right_stripped) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 64 | $new_path = $new_path . $directory_separator; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 128 | return $new_path; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 2 | 1; | |||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||