File Coverage

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