| 1 | package Sah::Schema::perl::modname; | ||
| 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 $schema = [str => { | ||
| 14 | summary => 'Perl module name, e.g. Foo::Bar', | ||
| 15 | description => <<'_', | ||
| 16 | |||
| 17 | This is a schema you can use when you want to accept a Perl module name. It | ||
| 18 | offers basic checking of syntax as well as a couple of conveniences. First, it | ||
| 19 | offers completion from list of locally installed Perl modules. Second, it | ||
| 20 | contains coercion rule so you can also input `Foo-Bar`, `Foo/Bar`, `Foo/Bar.pm` | ||
| 21 | or even 'Foo.Bar' and it will be normalized into `Foo::Bar`. | ||
| 22 | |||
| 23 | To see this schema in action on the CLI, you can try e.g. the `pmless` script | ||
| 24 | from <pm:App::PMUtils> and activate its tab completion (see its manpage for more | ||
| 25 | details). Then on the CLI try typing: | ||
| 26 | |||
| 27 | % pmless M/<tab> | ||
| 28 | % pmless dzp/<tab> | ||
| 29 | % pmless Module/List/Wildcard | ||
| 30 | % pmless Module::List::Wildcard | ||
| 31 | |||
| 32 | Note that this schema does not check that the Perl module exists or is installed | ||
| 33 | locally. To check that, use the `perl::modname::installed` schema. And there's | ||
| 34 | also a `perl::modname::not_installed` schema. | ||
| 35 | |||
| 36 | _ | ||
| 37 | match => '\\A(?:' . $Regexp::Pattern::Perl::Module::RE{perl_modname}{pat} . ')\\z', | ||
| 38 | |||
| 39 | 'prefilters' => [ | ||
| 40 | 'Perl::normalize_perl_modname', | ||
| 41 | ], | ||
| 42 | |||
| 43 | # provide a default completion which is from list of installed perl modules | ||
| 44 | 'x.completion' => 'perl_modname', | ||
| 45 | |||
| 46 | examples => [ | ||
| 47 | {value=>'', valid=>0}, | ||
| 48 | {value=>'Foo::Bar', valid=>1}, | ||
| 49 | {value=>'Foo-Bar', valid=>1, validated_value=>'Foo::Bar'}, | ||
| 50 | {value=>'Foo/Bar', valid=>1, validated_value=>'Foo::Bar'}, | ||
| 51 | {value=>'Foo//Bar', valid=>1, validated_value=>'Foo::Bar'}, | ||
| 52 | {value=>'Foo/Bar.pm', valid=>1, validated_value=>'Foo::Bar'}, | ||
| 53 | {value=>'Foo.Bar', valid=>1, validated_value=>'Foo::Bar'}, | ||
| 54 | {value=>'Foo|Bar', valid=>0}, | ||
| 55 | ], | ||
| 56 | |||
| 57 | }]; | ||
| 58 | |||
| 59 | 1; | ||
| 60 | # ABSTRACT: Perl module name, e.g. Foo::Bar | ||
| 61 | |||
| 62 | __END__ | ||