File Coverage

blib/lib/Path/Util.pm
Criterion Covered Total %
statement 14 16 87.5
branch 0 4 0.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 19 25 76.0


line stmt bran cond sub pod time code
1             package Path::Util;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2021-07-05'; # DATE
5             our $DIST = 'Path-Util'; # DIST
6             our $VERSION = '0.000002'; # VERSION
7              
8 1     1   98385 use strict;
  1         13  
  1         31  
9 1     1   5 use warnings;
  1         2  
  1         27  
10              
11 1     1   5 use Exporter 'import';
  1         1  
  1         173  
12             our @EXPORT_OK = qw(
13             basename
14             );
15              
16             sub basename {
17 1     1 1 13853 require File::Spec;
18              
19 1         3 my ($path, @suffixes) = @_;
20              
21             # TODO: we haven't canonicalize foo/bar/ -> foo/bar so basename(foo/bar/) ->
22             # ''.
23              
24 1         16 my (undef, undef, $file) = File::Spec->splitpath($path);
25 1         4 for my $s (@suffixes) {
26 0 0       0 my $re = ref($s) eq 'Regexp' ? qr/$s$/ : qr/\Q$s\E$/;
27 0 0       0 last if $file =~ s/$re//;
28             }
29 1         6 $file;
30             }
31              
32             1;
33             # ABSTRACT: Path functions
34              
35             __END__