File Coverage

blib/lib/Data/Sah/Coerce/perl/To_str/From_str/normalize_perl_distname.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_distname;
2              
3 1     1   7298 use 5.010001;
  1         4  
4 1     1   6 use strict;
  1         2  
  1         21  
5 1     1   4 use warnings;
  1         3  
  1         236  
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 13 v => 4,
15             summary => 'Coerce perl::distname from str',
16             prio => 50,
17             };
18             }
19              
20             sub coerce {
21 1     1 0 16 my %args = @_;
22              
23 1         3 my $dt = $args{data_term};
24              
25 1         1 my $res = {};
26              
27 1         4 $res->{expr_match} = "!ref($dt)";
28 1         5 $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 (@1.23) 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         4 $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_distname
54              
55             =head1 VERSION
56              
57             This document describes version 0.046 of Data::Sah::Coerce::perl::To_str::From_str::normalize_perl_distname (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.pm
64             Foo::Bar
65             Foo:Bar
66             Foo/Bar
67             Foo.Bar
68              
69             into:
70              
71             Foo-Bar
72              
73             =for Pod::Coverage ^(meta|coerce)$
74              
75             =head1 HOMEPAGE
76              
77             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Perl>.
78              
79             =head1 SOURCE
80              
81             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Perl>.
82              
83             =head1 AUTHOR
84              
85             perlancar <perlancar@cpan.org>
86              
87             =head1 CONTRIBUTING
88              
89              
90             To contribute, you can send patches by email/via RT, or send pull requests on
91             GitHub.
92              
93             Most of the time, you don't need to build the distribution yourself. You can
94             simply modify the code, then test via:
95              
96             % prove -l
97              
98             If you want to build the distribution (e.g. to try to install it locally on your
99             system), you can install L<Dist::Zilla>,
100             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
101             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
102             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
103             that are considered a bug and can be reported to me.
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =head1 BUGS
113              
114             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Perl>
115              
116             When submitting a bug or request, please include a test-file or a
117             patch to an existing test-file that illustrates the bug or desired
118             feature.
119              
120             =cut