File Coverage

blib/lib/Data/Sah/Filter/perl/Path/expand_tilde.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::expand_tilde;
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   133926 use 5.010001;
  3         12  
9 3     3   22 use strict;
  3         7  
  3         65  
10 3     3   17 use warnings;
  3         9  
  3         406  
11              
12             sub meta {
13             +{
14 3     3 0 42 v => 1,
15             target_type => 'str',
16             summary => "Expand tilde ('~' and '~USER' to user's home directory)",
17             };
18             }
19              
20             sub filter {
21 3     3 0 40 my %args = @_;
22              
23 3         9 my $dt = $args{data_term};
24              
25 3         8 my $res = {};
26              
27 3         11 $res->{expr_filter} = join(
28             "",
29             "do { my \$tmp = $dt; \$tmp =~ s!\\A~([^/]*)!my \@pw = length(\$1) ? getpwnam(\$1) : getpwuid(\$>); \@pw ? \$pw[7]: \"~\$1\"!e; \$tmp }",
30             );
31              
32 3         11 $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::expand_tilde
47              
48             =head1 VERSION
49              
50             This document describes version 0.014 of Data::Sah::Filter::perl::Path::expand_tilde (from Perl distribution Sah-Schemas-Path), released on 2020-08-08.
51              
52             =head1 DESCRIPTION
53              
54             This filter rule does tilde expansion (e.g. "~/foo" or "~budi/foo" to
55             "/home/budi/foo") normally performed by Unix shells like bash. Since these
56             tilde-containing paths might seep unexpanded beyond shells, this filter rule can
57             be quite convenient.
58              
59             =for Pod::Coverage ^(meta|filter)$
60              
61             =head1 HOMEPAGE
62              
63             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Path>.
64              
65             =head1 SOURCE
66              
67             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Path>.
68              
69             =head1 BUGS
70              
71             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Path>
72              
73             When submitting a bug or request, please include a test-file or a
74             patch to an existing test-file that illustrates the bug or desired
75             feature.
76              
77             =head1 AUTHOR
78              
79             perlancar <perlancar@cpan.org>
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2020, 2019, 2018, 2016 by perlancar@cpan.org.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut