Sah/Schema/perl/filename.pm

filter: Statementstmt 54.5% 12 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 51.8% 14 / 27 CC 2 SCAR 12.5
CC
2
Cov
50%
__ANON__
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« Data/Sah/Coerce/perl/To_array/From_str_or_array/expand_perl_modprefix_wildcard.pm ↑ Summary Sah/Schema/perl/pm_filename.pm »
1 package Sah::Schema::perl::filename;
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 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7 1 our $DATE = '2024-02-16'; # DATE
8 1 our $DIST = 'Sah-SchemaBundle-Perl'; # DIST
9 1 our $VERSION = '0.050'; # VERSION
10  
11 our $schema = [str => {
12 summary => 'Filename of Perl script/module/POD, e.g. /path/Foo/Bar.pm',
13 description => <<'_',
14  
15 Use this schema if you want to accept a filesystem path containing Perl script,
16 module, or POD. The value of this schema is in the convenience of CLI
17 completion, as well as coercion from script or module name.
18  
19 String containing filename of a Perl script or module or POD. For convenience,
20 when value is in the form of:
21  
22 Foo
23 Foo.pm
24 Foo.pod
25 Foo::Bar
26 Foo/Bar
27 Foo/Bar.pm
28 Foo/Bar.pod
29  
30 and a matching .pod or .pm file is found in `@INC`, then it will be coerced
31 (converted) into the path of that .pod/.pm file, e.g.:
32  
33 /home/ujang/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/Foo/Bar.pm
34 lib/Foo/Bar.pod
35  
36 To prevent such coercion, you can use prefixing path, e.g.:
37  
38 ./Foo::Bar
39 ../Foo/Bar
40 /path/to/Foo/Bar
41  
42 This schema comes with convenience completion too.
43  
44 _
45 'x.perl.coerce_rules' => [
46 'From_str::convert_perl_pm_or_pod_to_path',
47 ],
48 0 ▶ 'x.completion' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
49 0 require Complete::File;
50 0 require Complete::Module;
51 0 require Complete::Util;
52  
53 0 my %args = @_;
54 0 my $word = $args{word};
55  
56 0 my @answers;
57 0 push @answers, Complete::File::complete_file(word => $word);
58 0 ▶ if ($word =~ m!\A\w*((?:::|/)\w+)*\z!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ m[\A\w*((?:::|/)\w+)*\z]) 0 0 0
59 0 push @answers, Complete::Module::complete_module(word => $word);
60 }
61  
62 0 Complete::Util::combine_answers(@answers);
63 },
64  
65 1 }];
66  
67 1 1;
68 # ABSTRACT: Filename of Perl script/module/POD, e.g. /path/Foo/Bar.pm
69  
70 __END__
« Data/Sah/Coerce/perl/To_array/From_str_or_array/expand_perl_modprefix_wildcard.pm ↑ Summary Sah/Schema/perl/pm_filename.pm »