Pattern/Example.pm

filter: Statementstmt 100% 11 / 11 Branchbran 100% 2 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 18 / 18 CC 3 SCAR 9.2
CC
3
Cov
100%
__ANON__
3.0
BEGIN
1.0
CRAP 2.5
« Pattern.pm ↑ Summary
1 package Regexp::Pattern::Example;
2  
3 2 our $DATE = '2020-04-01'; # DATE
4 2 our $VERSION = '0.2.14'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # BEGIN_BLOCK: def
9  
10 our %RE = (
11 # the minimum spec
12 re1 => { pat => qr/\d{3}-\d{3}/ },
13  
14 # more complete spec
15 re2 => {
16 summary => 'This is regexp for blah', # plaintext
17 description => <<'_',
18  
19 A longer description in *Markdown* format.
20  
21 _
22 pat => qr/\d{3}-\d{3}(?:-\d{5})?/,
23 tags => ['A','B'],
24 examples => [
25 # examples can be tested using 'test-regexp-pattern' script
26 # (distributed in Test-Regexp-Pattern distribution). examples can
27 # also be rendered in your POD using
28 # Pod::Weaver::Plugin::Regexp::Pattern.
29 {
30 str => '123-456',
31 matches => 1,
32 },
33 {
34 summary => 'Another example that matches',
35 str => '123-456-78901',
36 matches => 1,
37 },
38 {
39 summary => 'An example that does not match',
40 str => '123456',
41 matches => 0,
42 },
43 {
44 summary => 'An example that does not get tested',
45 str => '123456',
46 },
47 {
48 summary => 'Another example that does not get tested nor rendered to POD',
49 str => '234567',
50 matches => 0,
51 test => 0,
52 doc => 0,
53 },
54 ],
55 },
56  
57 # dynamic (regexp generator)
58 re3 => {
59 summary => 'This is a regexp for blah blah',
60 description => <<'_',
61  
62 ...
63  
64 _
65 13 ▶ gen => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
66 13 my %args = @_;
67 13 ▶ my $variant = $args{variant} || 'A';
Condition100%2/2
$args{'variant'} || 'A'
l!l
310
MC/DC100%1/1
$args{'variant'} || 'A'
$args{'variant'}
Truth table100%2/2
A
A= $args{'variant'}
Aresult
11
00
68 13 ▶ if ($variant eq 'A') {
Branch: 1 branch
BranchTrueFalseTotal
if ($variant eq 'A') { } 11 2 13
69 11 return qr/\d{3}-\d{3}/;
70 } else { # B
71 2 return qr/\d{3}-\d{2}-\d{5}/;
72 }
73 },
74 2 gen_args => {
75 variant => {
76 summary => 'Choose variant',
77 schema => ['str*', in=>['A','B']],
78 default => 'A',
79 req => 1,
80 },
81 },
82 tags => ['B','C'],
83 examples => [
84 {
85 summary => 'An example that matches',
86 gen_args => {variant=>'A'},
87 str => '123-456',
88 matches => 1,
89 },
90 {
91 summary => "An example that doesn't match",
92 gen_args => {variant=>'B'},
93 str => '123-456',
94 matches => 0,
95 },
96 ],
97 },
98  
99 re4 => {
100 summary => 'This is a regexp that does capturing',
101 # it is recommended that your pattern does not capture, unless
102 # necessary. capturing pattern should tag with 'capturing' to let
103 # users/tools know.
104 tags => ['capturing'],
105 pat => qr/(\d{3})-(\d{3})/,
106 examples => [
107 {str=>'123-456', matches=>[123, 456]},
108 {str=>'foo-bar', matches=>[]},
109 ],
110 },
111  
112 re5 => {
113 summary => 'This is another regexp that is anchored and does (named) capturing',
114 # it is recommended that your pattern is not anchored for more
115 # reusability, unless necessary. anchored pattern should tag with
116 # 'anchored' to let users/tools know.
117 tags => ['capturing', 'anchored'],
118 pat => qr/^(?<cap1>\d{3})-(?<cap2>\d{3})/,
119 examples => [
120 {str=>'123-456', matches=>{cap1=>123, cap2=>456}},
121 {str=>'something 123-456', matches=>{}},
122 ],
123 },
124 );
125  
126 # END_BLOCK: def
127  
128 2 1;
129 # ABSTRACT: An example Regexp::Pattern::* module
130  
131 __END__
« Pattern.pm ↑ Summary