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