File Coverage

blib/lib/Data/Sah/Coerce/perl/To_str/From_str/normalize_perl_modname_or_prefix.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 20 22 90.9


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