Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add :strip parameter to IO::Pathy.basename
  • Loading branch information
lizmat committed Mar 11, 2015
1 parent d7c8a39 commit 8a5309b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/IO/Pathy.pm
Expand Up @@ -26,7 +26,16 @@ my role IO::Pathy {
@!parts = $!abspath.split('/') unless @!parts; # remove if above ok
@!parts[1 .. *-2].join('/');
}
method basename(IO::Pathy:D:) { MAKE-BASENAME($!abspath) }

proto method basename (|) { * }
multi method basename(IO::Pathy:D:) { MAKE-BASENAME($!abspath) }
multi method basename(IO::Pathy:D: :$strip!) {
my $basename := MAKE-BASENAME($!abspath);
my $ext := MAKE-EXT($basename);
$ext ~~ $strip.any
?? $basename.substr(0,*-($ext.chars + 1))
!! $basename;
}
method extension(IO::Pathy:D:) { MAKE-EXT(MAKE-BASENAME($!abspath))}

method parent(IO::Pathy:D: $levels = 1) {
Expand Down

0 comments on commit 8a5309b

Please sign in to comment.