File Coverage

blib/lib/Sah/Schema/re_from_str.pm
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1             package Sah::Schema::re_from_str;
2              
3 1     1   293158 use strict;
  1         2  
  1         113  
4              
5             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
6             our $DATE = '2023-12-20'; # DATE
7             our $DIST = 'Sah-Schemas-Re'; # DIST
8             our $VERSION = '0.006'; # VERSION
9              
10             our $schema = [
11             re => {
12             summary => 'Regexp object from string using Regexp::From::String\'s str_to_re()',
13             description => <<'MARKDOWN',
14              
15             This schema accepts Regexp object or string which will be coerced to Regexp object
16             using 's `str_to_re()` function.
17              
18             Basically, if string is of the form of `/.../` or `qr(...)`, then you could
19             specify metacharacters as if you are writing a literal regexp pattern in Perl.
20             Otherwise, your string will be `quotemeta()`-ed first then compiled to Regexp
21             object. This means in the second case you cannot specify metacharacters.
22              
23             What's the difference between this schema and `str_or_re` (from
24             )? Both this schema and `str_or_re` accept string, but
25             this schema will still coerce strings not in the form of `/.../` or `qr(...)` to
26             regexp object, while `str_or_re` will leave the string as-is. In other words,
27             this schema always converts input to Regexp object while `str_or_re` does not.
28              
29             MARKDOWN
30              
31             prefilters => [ ['Re::re_from_str'=>{}] ],
32              
33             examples => [
34             ],
35             },
36             ];
37              
38             1;
39             # ABSTRACT: Regexp object from string
40              
41             __END__