File Coverage

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