Sah/Schema/perl/pm_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
« Sah/Schema/perl/filename.pm ↑ Summary Sah/Schema/perl/pod_filename.pm »
1 package Sah::Schema::perl::pm_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 => 'A .pm filename, e.g. /path/Foo.pm',
13 description => <<'_',
14  
15 Use this schema if you want to accept a filesystem path containing Perl module.
16 The value of this schema is in the convenience of CLI completion, as well as
17 coercion from module name.
18  
19 String containing filename of a Perl module. For convenience, when value is in
20 the form of:
21  
22 Foo
23 Foo.pm
24 Foo::Bar
25 Foo/Bar
26 Foo/Bar.pm
27  
28 and a matching .pm file is found in `@INC`, then it will be coerced (converted)
29 into the path of that .pm file, e.g.:
30  
31 /home/ujang/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/Foo/Bar.pm
32  
33 To prevent such coercion, you can use prefixing path, e.g.:
34  
35 ./Foo::Bar
36 ../Foo/Bar
37 /path/to/Foo/Bar
38  
39 This schema comes with convenience completion too.
40  
41 _
42 'x.perl.coerce_rules' => [
43 'From_str::convert_perl_pm_to_path',
44 ],
45 0 ▶ 'x.completion' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
46 0 require Complete::File;
47 0 require Complete::Module;
48 0 require Complete::Util;
49  
50 0 my %args = @_;
51 0 my $word = $args{word};
52  
53 0 my @answers;
54 0 push @answers, Complete::File::complete_file(word => $word);
55 0 ▶ if ($word =~ m!\A\w*((?:::|/)\w+)*\z!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ m[\A\w*((?:::|/)\w+)*\z]) 0 0 0
56 0 push @answers, Complete::Module::complete_module(
57 word => $word, find_pod=>0);
58 }
59  
60 0 Complete::Util::combine_answers(@answers);
61 },
62  
63 1 }];
64  
65 1 1;
66 # ABSTRACT: A .pm filename, e.g. /path/Foo.pm
67  
68 __END__
« Sah/Schema/perl/filename.pm ↑ Summary Sah/Schema/perl/pod_filename.pm »