The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::RegexpPatternUtils - CLI utilities related to Regexp::Pattern

VERSION

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

SYNOPSIS

DESCRIPTION

This distribution includes several utilities related to Regexp::Pattern:

FUNCTIONS

get_regexp_pattern_pattern

Usage:

 get_regexp_pattern_pattern(%args) -> [$status_code, $reason, $payload, \%result_meta]

Get a Regexp::Pattern::* pattern.

Examples:

  • Example #1:

     get_regexp_pattern_pattern(pattern => "YouTube/video_id"); # -> [200, "OK", "(?^:[A-Za-z0-9_-]{11})", {}]
  • Generate variant A of Example::re3:

     get_regexp_pattern_pattern(pattern => "Example::re3", gen_args => { variant => "A" });

    Result:

     [200, "OK", "(?^:\\d{3}-\\d{3})", {}]
  • Generate variant B of Example::re3:

     get_regexp_pattern_pattern(pattern => "Example::re3", gen_args => { variant => "B" });

    Result:

     [200, "OK", "(?^:\\d{3}-\\d{2}-\\d{5})", {}]

This function is not exported.

Arguments ('*' denotes required arguments):

  • gen_args => hash

    Supply generator arguments.

    If pattern is a dynamic pattern (generated on-demand) and the generator requires some arguments, you can supply them here.

  • pattern* => regexppattern::name

    Name of pattern, with module prefix but without the 'Regexp::Pattern'.

Returns an enveloped result (an array).

First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.

Return value: (any)

list_regexp_pattern_modules

Usage:

 list_regexp_pattern_modules() -> [$status_code, $reason, $payload, \%result_meta]

List all installed Regexp::Pattern::* modules.

This function is not exported.

No arguments.

Returns an enveloped result (an array).

First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.

Return value: (any)

match_with_regexp_pattern

Usage:

 match_with_regexp_pattern(%args) -> [$status_code, $reason, $payload, \%result_meta]

Match a string against a Regexp::Pattern pattern.

Examples:

  • A non-match:

     match_with_regexp_pattern(pattern => "YouTube/video_id", string => "foo");

    Result:

     [
       200,
       "OK",
       "String DOES NOT match regexp pattern YouTube::video_id",
       { "cmdline.exit_code" => 1 },
     ]
  • A match:

     match_with_regexp_pattern(pattern => "YouTube/video_id", string => "Yb4EGj4_uS0");

    Result:

     [
       200,
       "OK",
       "String matches regexp pattern YouTube::video_id",
       { "cmdline.exit_code" => 0 },
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • anchor => bool

    Generate an anchored version of the pattern.

  • captures => bool

    Return array of captures instead of just a boolean status.

  • gen_args => hash

    Supply generator arguments.

    If pattern is a dynamic pattern (generated on-demand) and the generator requires some arguments, you can supply them here.

  • pattern* => regexppattern::name

    Name of pattern, with module prefix but without the 'Regexp::Pattern'.

  • quiet => bool

  • string* => str

Returns an enveloped result (an array).

First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.

Return value: (any)

HOMEPAGE

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

SOURCE

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

SEE ALSO

Other CLI's included in other distributions:

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2020, 2018, 2016 by perlancar <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.

BUGS

Please report any bugs or feature requests on the bugtracker website 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 feature.