Sah/Schema/perl/modname_with_optional_args.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Sah/Schema/perl/modname_pm.pm ↑ Summary Sah/Schema/perl/distname.pm »
1 package Sah::Schema::perl::modname_with_optional_args;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7 our $DATE = '2024-02-16'; # DATE
8 our $DIST = 'Sah-SchemaBundle-Perl'; # DIST
9 our $VERSION = '0.050'; # VERSION
10  
11 0 ▶use Regexp::Pattern::Perl::Module ();
Subroutine BEGIN: called CC=1 SCAR=2.6
12  
13 our @examples_str = (
14 {value=>'', valid=>0},
15 {value=>'Foo::Bar', valid=>1},
16 {value=>'Foo::Bar=arg1,arg2', valid=>1},
17 {value=>'Foo-Bar=arg1,arg2', valid=>1, validated_value=>'Foo::Bar=arg1,arg2'},
18 #{value=>'Foo::Bar=arg1,arg2 foo', valid=>0}, # XXX why fail?
19 );
20  
21 our @examples_array = (
22 {value=>[], valid=>0, summary=>"No module name"},
23 {value=>["Foo"], valid=>1},
24 {value=>["Foo Bar"], valid=>0, summary=>"Invalid module name"},
25 {value=>["Foo","arg"], valid=>0, summary=>"Args must be arrayref or hashref"},
26 {value=>["Foo",{arg1=>1, arg2=>2}], valid=>1},
27 {value=>["Foo",["arg1","arg2"]], valid=>1},
28 {value=>["Foo",["arg1","arg2"],{}], valid=>0, summary=>"Too many elements"},
29 );
30  
31 our $schema_str = [str => {
32 summary => 'Perl module name (e.g. Foo::Bar) with optional arguments (e.g. Foo::Bar=arg1,arg2)',
33 description => <<'_',
34  
35 Perl module name with optional arguments which will be used as import arguments,
36 just like the `-MMODULE=ARGS` shortcut that `perl` provides. Examples:
37  
38 Foo
39 Foo::Bar
40 Foo::Bar=arg1,arg2
41  
42 See also: `perl::modname`.
43  
44 _
45 match => '\\A(?:' . $Regexp::Pattern::Perl::Module::RE{perl_modname_with_optional_args}{pat} . ')\\z',
46  
47 'x.perl.coerce_rules' => [
48 'From_str::normalize_perl_modname',
49 ],
50  
51 # XXX also provide completion for arguments
52 'x.completion' => 'perl_modname',
53  
54 examples => \@examples_str,
55 }];
56  
57 our $schema_array = [array_from_json => {
58 summary => 'A 1- or 2-element array containing Perl module name (e.g. ["Foo::Bar"]) with optional arguments (e.g. ["Foo::Bar", ["arg1","arg2"]])',
59 description => <<'_',
60  
61 These are valid values for this schema:
62  
63 ["Foo"] # just the module name
64 ["Foo::Bar", ["arg1","arg2"]] # with import arguments (array)
65 ["Foo::Bar", {"arg1"=>"val","arg2"=>"val"}] # with import arguments (hash)
66  
67 _
68 min_len => 1,
69 max_len => 2,
70 elems => [
71 ["perl::modname",{req=>1}],
72 ["any", {
73 req=>1,
74 of=>[
75 ["array",{req=>1}],
76 ["hash",{req=>1}]],
77 }],
78 ],
79 examples => \@examples_array,
80 }];
81  
82 our $schema = [any => {
83 summary => 'Perl module name (e.g. Foo::Bar) with optional arguments (e.g. Foo::Bar=arg1,arg2)',
84 description => <<'_',
85  
86 Perl module name with optional arguments which will be used as import arguments,
87 just like the `-MMODULE=ARGS` shortcut that `perl` provides. Examples:
88  
89 Foo
90 Foo::Bar
91 Foo::Bar=arg1,arg2
92  
93 See also: `perl::modname`.
94 A two-element array from (coercible from JSON string) is also allowed:
95  
96 ["Foo::Bar", \@args]
97  
98 _
99 of => [
100 $schema_array,
101 $schema_str,
102 ],
103  
104 # XXX also provide completion for arguments
105 'x.completion' => 'perl_modname',
106  
107 examples => [
108 @examples_str,
109 @examples_array,
110 ],
111 }];
112  
113 1;
114 # ABSTRACT: Perl module name (e.g. Foo::Bar) with optional arguments (e.g. Foo::Bar=arg1,arg2)
115  
116 __END__
« Sah/Schema/perl/modname_pm.pm ↑ Summary Sah/Schema/perl/distname.pm »