our $DATE = '2021-06-27'; # DATE
our $DIST = 'App-RegexpPatternUtils'; # DIST
our $VERSION = '0.006'; # VERSION

use 5.010001;
use strict 'subs', 'vars';
use warnings;
use Perinci::CmdLine::Any;

our %SPEC;

$SPEC{app} = {
    v => 1.1,
    summary => 'Show declaration from Regexp::Pattern::* module',
    args => {
        name => {
            summary => 'Regexp::Pattern::* module without the "Regexp::Pattern::" prefix',
            schema => 'perl::modname*',
            pos => 0,
            completion => sub {
                my %args = @_;
                require 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) {
            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",
        } else {
            return [200, "OK", $var];
    } else {
        return [400, "Please specify name of a Regexp Pattern module (or -l)"];

    url => '/main/app',
    pass_cmdline_object => 1,
    read_config => 0,
    read_env => 0,
    use_locale => 1,

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



=encoding UTF-8

=head1 NAME

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

=head1 VERSION

This document describes version 0.006 of show-regexp-pattern-module (from Perl distribution App-RegexpPatternUtils), released on 2021-06-27.



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

=head1 OPTIONS

C<*> marks required options.

=head2 Main options


=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.


=head2 Output options


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

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

Default value:


=item B<--json>

Set output format to json.

=item B<--naked-res>

When outputing as JSON, strip result envelope.

Default value:


By default, when outputing as JSON, the full enveloped result is returned, e.g.:


The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
`--naked-res` so you just get:


=item B<--page-result>

Filter output through a pager.

=item B<--view-result>

View output using a viewer.


=head2 Other options


=item B<--help>, B<-h>, B<-?>

Display help message and exit.

=item B<--version>, B<-v>

Display program's version and exit.



This script has shell tab completion capability with support for several

=head2 bash

To activate bash completion for this script, put:

 complete -C show-regexp-pattern-module show-regexp-pattern-module

in your bash startup (e.g. F<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is recommended, however, that you install modules using L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete show-regexp-pattern-module 'p/*/`show-regexp-pattern-module`/'

in your tcsh startup (e.g. F<~/.tcshrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is also recommended to install L<shcompgen> (see above).

=head2 other shells

For fish and zsh, install L<shcompgen> as described above.


Please visit the project's homepage at L<https://metacpan.org/release/App-RegexpPatternUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-RegexpPatternUtils>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-RegexpPatternUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired

=head1 SEE ALSO


=head1 AUTHOR

perlancar <perlancar@cpan.org>


This software is copyright (c) 2021, 2020, 2018, 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.