File Coverage

blib/lib/Data/Sah/Filter/perl/Path/strip_slashes.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 19 21 90.4


line stmt bran cond sub pod time code
1             package Data::Sah::Filter::perl::Path::strip_slashes;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-08-08'; # DATE
5             our $DIST = 'Sah-Schemas-Path'; # DIST
6             our $VERSION = '0.014'; # VERSION
7              
8 3     3   1577 use 5.010001;
  3         16  
9 3     3   20 use strict;
  3         10  
  3         82  
10 3     3   20 use warnings;
  3         12  
  3         427  
11              
12             sub meta {
13             +{
14 3     3 0 36 v => 1,
15             target_type => 'str',
16             summary => 'Strip extra and trailing slash from a string',
17             };
18             }
19              
20             sub filter {
21 3     3 0 37 my %args = @_;
22              
23 3         10 my $dt = $args{data_term};
24              
25 3         6 my $res = {};
26              
27 3         12 $res->{expr_filter} = join(
28             "",
29             "do { my \$tmp = $dt; \$tmp =~ s!/{2,}!/!g; \$tmp =~ s!/\\z!!g unless \$tmp =~ m!\\A/\\z!; \$tmp }",
30             );
31              
32 3         9 $res;
33             }
34              
35             1;
36             # ABSTRACT:
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Data::Sah::Filter::perl::Path::strip_slashes
47              
48             =head1 VERSION
49              
50             This document describes version 0.014 of Data::Sah::Filter::perl::Path::strip_slashes (from Perl distribution Sah-Schemas-Path), released on 2020-08-08.
51              
52             =head1 DESCRIPTION
53              
54             This filter rule removes extra slashes (e.g. "/foo//bar" becomes "/foo/bar") and
55             trailing slash.
56              
57             Regarding trailing slash: functions might not expect a filename or dirname to
58             have a trailing slash (e.g. C<-d>, C<opendir()>, etc will not work if we add
59             slash to a directory name), but shell tab completion usually adds a trailing
60             slash. So this filter rule provides the convenience of stripping the trailing
61             slash for the functions.
62              
63             =for Pod::Coverage ^(meta|filter)$
64              
65             =head1 HOMEPAGE
66              
67             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Path>.
68              
69             =head1 SOURCE
70              
71             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Path>.
72              
73             =head1 BUGS
74              
75             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Path>
76              
77             When submitting a bug or request, please include a test-file or a
78             patch to an existing test-file that illustrates the bug or desired
79             feature.
80              
81             =head1 AUTHOR
82              
83             perlancar <perlancar@cpan.org>
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is copyright (c) 2020, 2019, 2018, 2016 by perlancar@cpan.org.
88              
89             This is free software; you can redistribute it and/or modify it under
90             the same terms as the Perl 5 programming language system itself.
91              
92             =cut