| 1 | package File::Basename::Object; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | use overload | ||||||||||
| 7 | 1 | ▶ | '""' => \&_as_string, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 'cmp' => \&_compare, | ||||||||||
| 9 | '<=>' => \&_compare_basename, | ||||||||||
| 10 | fallback => 1, | ||||||||||
| 11 | 1 | ; | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use File::Basename (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | our $VERSION = '0.01'; | |||||||||
| 16 | |||||||||||
| 17 | 1 | return 1; | |||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 20 | 5 | my $class = shift; | |||||||||
| 21 | 5 | return bless [ @_ ], $class; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 15 | ▶ | sub fullname { | ||||||||
|
Subroutine
fullname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 15 | my($self, $path) = @_; | |||||||||
| 26 | 15 | my $old_path = $self->[0]; | |||||||||
| 27 | 15 | ▶ | $self->[0] = $path if(@_ > 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 15 | return $old_path; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 14 | ▶ | sub suffixlist { | ||||||||
|
Subroutine
suffixlist: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 32 | 14 | my($self, @suffixes) = @_; | |||||||||
| 33 | 14 | my @old_suffixes = @{$self}[$[ + 1 .. $#$self]; | |||||||||
| 34 | 14 | ▶ | splice(@$self, $[ + 1, $#$self, @suffixes) if(@_ > 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 14 | return @old_suffixes; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 1 | ▶ | sub no_suffixes { | ||||||||
|
Subroutine
no_suffixes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 39 | 1 | my $self = shift; | |||||||||
| 40 | 1 | return splice(@$self, 1); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | ▶ | sub copy { | ||||||||
|
Subroutine
copy: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 2 | my $self = shift; | |||||||||
| 45 | 2 | my $rv = ref($self)->new(@$self); | |||||||||
| 46 | 2 | ▶ | if(my $path = shift) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | $rv->fullname($path); | |||||||||
| 48 | } | ||||||||||
| 49 | 2 | return $rv; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 8 | ▶ | sub _as_string { | ||||||||
|
Subroutine
_as_string: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 8 | my $self = shift; | |||||||||
| 54 | 8 | return $self->[0]; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 11 | ▶ | sub fileparse { | ||||||||
|
Subroutine
fileparse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 11 | my $self = shift; | |||||||||
| 59 | 11 | return File::Basename::fileparse($self->fullname, $self->suffixlist); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | ▶ | sub basename { | ||||||||
|
Subroutine
basename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 63 | 1 | my $self = shift; | |||||||||
| 64 | 1 | return File::Basename::basename($self->fullname, $self->suffixlist); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | sub dirname { | ||||||||
|
Subroutine
dirname: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 1 | my $self = shift; | |||||||||
| 69 | 1 | return File::Basename::dirname($self->fullname, $self->suffixlist); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 4 | ▶ | sub _compare { | ||||||||
|
Subroutine
_compare: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 4 | my($a, $b) = @_; | |||||||||
| 74 | 4 | return "$a" cmp "$b"; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 7 | ▶ | sub _compare_basename { | ||||||||
|
Subroutine
_compare_basename: called CC=2 SCAR=6.9
| |||||||||||
| 78 | 7 | my($a, $b) = @_; | |||||||||
| 79 | 7 | ▶ | if(UNIVERSAL::isa($b, __PACKAGE__)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 5 | return scalar($a->fileparse) cmp scalar($b->fileparse); | |||||||||
| 81 | } else { | ||||||||||
| 82 | 2 | return $a->_compare_basename(__PACKAGE__->new($b, @{$a}[ $[ + 1 .. $#$a ])); | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||