App-RegexpPatternUtils

 view release on metacpan or  search on metacpan

script/show-regexp-pattern-module  view on Meta::CPAN

    args => {
        name => {
            summary => 'Regexp::Pattern::* module without the "Regexp::Pattern::" prefix',
            schema => 'perl::modname*',
            pos => 0,
            completion => sub {
                my %args = @_;
                require Complete::Module;
                Complete::Module::complete_module(
                    word => $args{word},
                    ns_prefix => 'Regexp::Pattern',
                );
            },
        },
        list => {
            schema => ['bool', is=>1],
            cmdline_aliases => {l=>{}},
        },
    },
};
sub app {
    my %args = @_;

    my $name = $args{name};

    if ($args{list}) {
        my @res;
        require Module::List::Tiny;
        my $res = Module::List::Tiny::list_modules(
            'Regexp::Pattern::', {list_modules=>1, recurse=>1});
        for (sort keys %$res) {
            s/\ARegexp::Pattern:://;
            push @res, $_;
        }
        return [200, "OK", \@res];
    } elsif ($name) {
        $name =~ /\A\w+(::\w+)*\z/
            or return [400, "Invalid module name '$name'"];;
        $name = "Regexp::Pattern::$name";
        (my $name_pm = "$name.pm") =~ s!::!/!g;
        require $name_pm;
        my $var = \%{"$name\::RE"};
        if ($args{-cmdline} &&
                ($args{-cmdline_r}{format} // 'text') =~ /text/) {
            require Data::Dump::Color;
            return [200, "OK", Data::Dump::Color::dump($var) . "\n",
                    {'cmdline.skip_format'=>1}];
        } else {
            return [200, "OK", $var];
        }
    } else {
        return [400, "Please specify name of a Regexp Pattern module (or -l)"];
    }
}

Perinci::CmdLine::Any->new(
    url => '/main/app',
    pass_cmdline_object => 1,
    read_config => 0,
    read_env => 0,
    use_locale => 1,
)->run;

# ABSTRACT: Show declaration from Regexp::Pattern::* module
# PODNAME: show-regexp-pattern-module

__END__

=pod

=encoding UTF-8

=head1 NAME

show-regexp-pattern-module - Show declaration from Regexp::Pattern::* module

=head1 VERSION

This document describes version 0.008 of show-regexp-pattern-module (from Perl distribution App-RegexpPatternUtils), released on 2022-05-08.

=head1 SYNOPSIS

Usage:

% B<show-regexp-pattern-module> [B<--format>=I<name>|B<--json>] [B<--list>|B<-l>] [B<--(no)naked-res>] [B<--page-result>[=I<program>]|B<--view-result>[=I<program>]] -- [I<name>]

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--list>, B<-l>

=item B<--name>=I<s>

Regexp::Pattern::* module without the "Regexp::Pattern::" prefix.

Can also be specified as the 1st command-line argument.

=back

=head2 Output options

=over

=item B<--format>=I<s>

Choose output format, e.g. json, text.

Default value:

 undef

=item B<--json>

Set output format to json.

=item B<--naked-res>



( run in 1.207 second using v1.01-cache-2.11-cpan-5735350b133 )