File Coverage

blib/lib/Sah/Schema/perl/funcname.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   38794 use warnings;
  1         2  
  1         27  
4 1     1   5  
  1         2  
  1         94  
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2021-12-01'; # DATE
7             our $DIST = 'Sah-Schemas-Perl'; # DIST
8             our $VERSION = '0.042'; # VERSION
9              
10             our $schema = [str => {
11             summary => 'Perl function name, either qualified with package name (e.g. Foo::subname) or unqualified (e.g. subname)',
12             description => <<'_',
13              
14             Currently function name is restricted to this regex:
15              
16             \A[A-Za-z_][A-Za-z_0-9]*\z
17              
18             Function name can be qualified (prefixed) by a package name, which is restricted
19             to this regex:
20              
21             [A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*
22              
23             _
24             match => '\A(?:[A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*::)?[A-Za-z_]([A-Za-z_0-9]+)*\z',
25              
26             # TODO: provide convenience by providing list of core function names etc
27             #'x.completion' => 'perl_funcname',
28              
29             }];
30              
31             1;
32             # ABSTRACT: Perl function name, either qualified with package name (e.g. Foo::subname) or unqualified (e.g. subname)
33              
34              
35             =pod
36              
37             =encoding UTF-8
38              
39             =head1 NAME
40              
41             Sah::Schema::perl::funcname - Perl function name, either qualified with package name (e.g. Foo::subname) or unqualified (e.g. subname)
42              
43             =head1 VERSION
44              
45             This document describes version 0.042 of Sah::Schema::perl::funcname (from Perl distribution Sah-Schemas-Perl), released on 2021-12-01.
46              
47             =head1 SYNOPSIS
48              
49             To check data against this schema (requires L<Data::Sah>):
50              
51             use Data::Sah qw(gen_validator);
52             my $validator = gen_validator("perl::funcname*");
53             say $validator->($data) ? "valid" : "INVALID!";
54              
55             # Data::Sah can also create validator that returns nice error message string
56             # and/or coerced value. Data::Sah can even create validator that targets other
57             # language, like JavaScript. All from the same schema. See its documentation
58             # for more details.
59              
60             To validate function parameters against this schema (requires L<Params::Sah>):
61              
62             use Params::Sah qw(gen_validator);
63              
64             sub myfunc {
65             my @args = @_;
66             state $validator = gen_validator("perl::funcname*");
67             $validator->(\@args);
68             ...
69             }
70              
71             To specify schema in L<Rinci> function metadata and use the metadata with
72             L<Perinci::CmdLine> to create a CLI:
73              
74             # in lib/MyApp.pm
75             package MyApp;
76             our %SPEC;
77             $SPEC{myfunc} = {
78             v => 1.1,
79             summary => 'Routine to do blah ...',
80             args => {
81             arg1 => {
82             summary => 'The blah blah argument',
83             schema => ['perl::funcname*'],
84             },
85             ...
86             },
87             };
88             sub myfunc {
89             my %args = @_;
90             ...
91             }
92             1;
93              
94             # in myapp.pl
95             package main;
96             use Perinci::CmdLine::Any;
97             Perinci::CmdLine::Any->new(url=>'MyApp::myfunc')->run;
98              
99             # in command-line
100             % ./myapp.pl --help
101             myapp - Routine to do blah ...
102             ...
103              
104             % ./myapp.pl --version
105              
106             % ./myapp.pl --arg1 ...
107              
108             =head1 DESCRIPTION
109              
110             Currently function name is restricted to this regex:
111              
112             \A[A-Za-z_][A-Za-z_0-9]*\z
113              
114             Function name can be qualified (prefixed) by a package name, which is restricted
115             to this regex:
116              
117             [A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*
118              
119             =head1 HOMEPAGE
120              
121             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Perl>.
122              
123             =head1 SOURCE
124              
125             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Perl>.
126              
127             =head1 SEE ALSO
128              
129             L<Sah::Schema::perl::qualified_funcname>
130              
131             L<Sah::Schema::perl::unqualified_funcname>
132              
133             =head1 AUTHOR
134              
135             perlancar <perlancar@cpan.org>
136              
137             =head1 CONTRIBUTING
138              
139              
140             To contribute, you can send patches by email/via RT, or send pull requests on
141             GitHub.
142              
143             Most of the time, you don't need to build the distribution yourself. You can
144             simply modify the code, then test via:
145              
146             % prove -l
147              
148             If you want to build the distribution (e.g. to try to install it locally on your
149             system), you can install L<Dist::Zilla>,
150             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
151             Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required
152             beyond that are considered a bug and can be reported to me.
153              
154             =head1 COPYRIGHT AND LICENSE
155              
156             This software is copyright (c) 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>.
157              
158             This is free software; you can redistribute it and/or modify it under
159             the same terms as the Perl 5 programming language system itself.
160              
161             =head1 BUGS
162              
163             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Perl>
164              
165             When submitting a bug or request, please include a test-file or a
166             patch to an existing test-file that illustrates the bug or desired
167             feature.
168              
169             =cut