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   45733 use warnings;
  1         2  
  1         26  
4 1     1   5  
  1         1  
  1         96  
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2022-09-11'; # DATE
7             our $DIST = 'Sah-Schemas-Perl'; # DIST
8             our $VERSION = '0.045'; # 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.045 of Sah::Schema::perl::funcname (from Perl distribution Sah-Schemas-Perl), released on 2022-09-11.
46              
47             =head1 SYNOPSIS
48              
49             =head2 Using with Data::Sah
50              
51             To check data against this schema (requires L<Data::Sah>):
52              
53             use Data::Sah qw(gen_validator);
54             my $validator = gen_validator("perl::funcname*");
55             say $validator->($data) ? "valid" : "INVALID!";
56              
57             The above schema returns a boolean result (true if data is valid, false if
58             otherwise). To return an error message string instead (empty string if data is
59             valid, a non-empty error message otherwise):
60              
61             my $validator = gen_validator("perl::funcname", {return_type=>'str_errmsg'});
62             my $errmsg = $validator->($data);
63              
64             Often a schema has coercion rule or default value, so after validation the
65             validated value is different. To return the validated (set-as-default, coerced,
66             prefiltered) value:
67              
68             my $validator = gen_validator("perl::funcname", {return_type=>'str_errmsg+val'});
69             my $res = $validator->($data); # [$errmsg, $validated_val]
70              
71             Data::Sah can also create validator that returns a hash of detailed error
72             message. Data::Sah can even create validator that targets other language, like
73             JavaScript, from the same schema. Other things Data::Sah can do: show source
74             code for validator, generate a validator code with debug comments and/or log
75             statements, generate human text from schema. See its documentation for more
76             details.
77              
78             =head2 Using with Params::Sah
79              
80             To validate function parameters against this schema (requires L<Params::Sah>):
81              
82             use Params::Sah qw(gen_validator);
83              
84             sub myfunc {
85             my @args = @_;
86             state $validator = gen_validator("perl::funcname*");
87             $validator->(\@args);
88             ...
89             }
90              
91             =head2 Using with Perinci::CmdLine::Lite
92              
93             To specify schema in L<Rinci> function metadata and use the metadata with
94             L<Perinci::CmdLine> (L<Perinci::CmdLine::Lite>) to create a CLI:
95              
96             # in lib/MyApp.pm
97             package
98             MyApp;
99             our %SPEC;
100             $SPEC{myfunc} = {
101             v => 1.1,
102             summary => 'Routine to do blah ...',
103             args => {
104             arg1 => {
105             summary => 'The blah blah argument',
106             schema => ['perl::funcname*'],
107             },
108             ...
109             },
110             };
111             sub myfunc {
112             my %args = @_;
113             ...
114             }
115             1;
116              
117             # in myapp.pl
118             package
119             main;
120             use Perinci::CmdLine::Any;
121             Perinci::CmdLine::Any->new(url=>'/MyApp/myfunc')->run;
122              
123             # in command-line
124             % ./myapp.pl --help
125             myapp - Routine to do blah ...
126             ...
127              
128             % ./myapp.pl --version
129              
130             % ./myapp.pl --arg1 ...
131              
132             =head1 DESCRIPTION
133              
134             Currently function name is restricted to this regex:
135              
136             \A[A-Za-z_][A-Za-z_0-9]*\z
137              
138             Function name can be qualified (prefixed) by a package name, which is restricted
139             to this regex:
140              
141             [A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9]+)*
142              
143             =head1 HOMEPAGE
144              
145             Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Perl>.
146              
147             =head1 SOURCE
148              
149             Source repository is at L<https://github.com/perlancar/perl-Sah-Schemas-Perl>.
150              
151             =head1 SEE ALSO
152              
153             L<Sah::Schema::perl::qualified_funcname>
154              
155             L<Sah::Schema::perl::unqualified_funcname>
156              
157             =head1 AUTHOR
158              
159             perlancar <perlancar@cpan.org>
160              
161             =head1 CONTRIBUTING
162              
163              
164             To contribute, you can send patches by email/via RT, or send pull requests on
165             GitHub.
166              
167             Most of the time, you don't need to build the distribution yourself. You can
168             simply modify the code, then test via:
169              
170             % prove -l
171              
172             If you want to build the distribution (e.g. to try to install it locally on your
173             system), you can install L<Dist::Zilla>,
174             L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
175             L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
176             Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
177             that are considered a bug and can be reported to me.
178              
179             =head1 COPYRIGHT AND LICENSE
180              
181             This software is copyright (c) 2022, 2021, 2020, 2019, 2018, 2017, 2016 by perlancar <perlancar@cpan.org>.
182              
183             This is free software; you can redistribute it and/or modify it under
184             the same terms as the Perl 5 programming language system itself.
185              
186             =head1 BUGS
187              
188             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-Perl>
189              
190             When submitting a bug or request, please include a test-file or a
191             patch to an existing test-file that illustrates the bug or desired
192             feature.
193              
194             =cut