File Coverage

blib/lib/Data/Sah/Coerce/perl/To_str/From_str/convert_perl_pod_or_pm_to_path.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 2 0.0
total 22 25 88.0


line stmt bran cond sub pod time code
1              
2             use 5.010001;
3 1     1   6262 use strict;
  1         4  
4 1     1   4 use warnings;
  1         2  
  1         20  
5 1     1   4  
  1         2  
  1         208  
6             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7             our $DATE = '2021-12-01'; # DATE
8             our $DIST = 'Sah-Schemas-Perl'; # DIST
9             our $VERSION = '0.042'; # VERSION
10              
11             +{
12             v => 4,
13             summary => 'Convert POD/module name existing in @INC to its filesystem path',
14 1     1 0 11 prio => 50,
15             };
16             }
17              
18             my %args = @_;
19              
20             my $dt = $args{data_term};
21 1     1 0 15  
22             my $res = {};
23 1         2  
24             $res->{modules}{'Module::Path::More'} //= {version=>0, core=>0, pp=>1};
25 1         2 $res->{expr_match} = "1";
26             $res->{expr_coerce} = join(
27 1   50     9 "",
28 1         2 "do { ",
29 1         5 "my \$_sahc_orig = $dt; ",
30             "if (\$_sahc_orig =~ m!\\A\\w+((?:/|::)\\w+)*(?:\\.pm|\\.pod)?\\z!) {",
31             " (my \$tmp = \$_sahc_orig) =~ s!/!::!g; my \$ext; \$tmp =~ s/\\.(pm|pod)\\z// and \$ext = \$1;",
32             " Module::Path::More::module_path(module=>\$tmp, find_pm=>!\$ext || \$ext eq 'pm' ? 2:0, find_pod=>!\$ext || \$ext eq 'pod' ? 1:0, find_prefix=>0, find_pmc=>0) || \$_sahc_orig ",
33             "} else {",
34             " \$_sahc_orig ",
35             "} ",
36             "}",
37             );
38              
39             $res;
40             }
41              
42 1         4 1;
43             # ABSTRACT:
44              
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Data::Sah::Coerce::perl::To_str::From_str::convert_perl_pod_or_pm_to_path
53              
54             =head1 VERSION
55              
56             This document describes version 0.042 of Data::Sah::Coerce::perl::To_str::From_str::convert_perl_pod_or_pm_to_path (from Perl distribution Sah-Schemas-Perl), released on 2021-12-01.
57              
58             =head1 DESCRIPTION
59              
60             This rule can convert strings in the form of:
61              
62             Foo::Bar
63             Foo/Bar
64             Foo/Bar.pod
65             Foo/Bar.pm
66              
67             into the filesystem path (e.g.
68             C</home/ujang/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/Foo/Bar.pm>)
69             when the POD or module exists in C<@INC>. Otherwise, it leaves the string as-is.
70              
71             This rule is the same as
72             L<Data::Sah::Coerce::perl::To_str::From_str::convert_perl_pm_or_pod_to_path> except that
73             .pod is prioritized over .pm. If C<Foo.pm> and C<Foo.pod> are both found on the
74             filesystem, C<Foo.pod> will be returned.
75              
76             =for Pod::Coverage ^(meta|coerce)$
77              
78             =head1 HOMEPAGE
79              
80             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Perl>.
81              
82             =head1 SOURCE
83              
84             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Perl>.
85              
86             =head1 AUTHOR
87              
88             perlancar <perlancar@cpan.org>
89              
90             =head1 CONTRIBUTING
91              
92              
93             To contribute, you can send patches by email/via RT, or send pull requests on
94             GitHub.
95              
96             Most of the time, you don't need to build the distribution yourself. You can
97             simply modify the code, then test via:
98              
99             % prove -l
100              
101             If you want to build the distribution (e.g. to try to install it locally on your
102             system), you can install L<Dist::Zilla>,
103             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
104             Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required
105             beyond that are considered a bug and can be reported to me.
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =head1 BUGS
115              
116             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Perl>
117              
118             When submitting a bug or request, please include a test-file or a
119             patch to an existing test-file that illustrates the bug or desired
120             feature.
121              
122             =cut