Brick/Regexes.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran 25.0% 1 / 4 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 72.0% 31 / 43 CC 5 SCAR 13.2
CC
5
Cov
76%
_matches_regex
6.0
__ANON__
6.0
BEGIN
1.0
CRAP 3.7
« Brick/Strings.pm ↑ Summary Brick/Numbers.pm »
1 package Brick::Regexes;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 $VERSION = '0.904';
8  
9 package Brick::Bucket;
10 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =encoding utf8
15  
16 =head1 NAME
17  
18 Brick - This is the description
19  
20 =head1 SYNOPSIS
21  
22 use Brick::Constraints;
23  
24 =head1 DESCRIPTION
25  
26 See C<Brick::Constraints> for the general discussion of constraint
27 creation.
28  
29 =head2 Utilities
30  
31 =over 4
32  
33 =item _matches_regex( HASHREF )
34  
35 Create a code ref to apply a regular expression to the named field.
36  
37 field - the field to apply the regular expression to
38 regex - a reference to a regular expression object ( qr// )
39  
40 =cut
41  
42 sub _matches_regex {
43 2 ▶ my( $bucket, $setup ) = @_;
Subroutine _matches_regex: called CC=4 SCAR=17.9
44  
45 2 my @caller = $bucket->__caller_chain_as_list();
46  
47 2 ▶ unless( eval { $setup->{regex}->isa( ref qr// ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $setup->{"regex"}->isa(ref qr//) } }) 0 2 2
48 0 croak( "Argument to $caller[0]{'sub'} must be a regular expression object" );
49 }
50  
51 $bucket->add_to_bucket ( {
52 name => $setup->{name} || $caller[0]{'sub'},
53 description => ( $setup->{description} || "Match a regular expression" ),
54 fields => [ $setup->{field} ],
55 code => sub {
56 die {
57 message => "[$_[0]->{ $setup->{field} }] did not match the pattern",
58 failed_field => $setup->{field},
59 failed_value => $_[0]->{ $setup->{field} },
60 handler => $caller[0]{'sub'},
61 0 ▶ } unless $_[0]->{ $setup->{field} } =~ m/$setup->{regex}/;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{$setup->{"field"}} =~ /$setup->{"regex"}/ 0 0 0
62 },
63 2 ▶ } );
Condition40%2/5
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
200
$setup->{'description'} || 'Match a regular expression'
l!l
20
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
MC/DC0%0/1
$setup->{'description'} || 'Match a regular expression'
$setup->{'description'}
Truth table33%1/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $setup->{'description'}
Aresult
11
00
64  
65 }
66  
67 =back
68  
69 =head1 TO DO
70  
71 Regex::Common support
72  
73 =head1 SEE ALSO
74  
75 TBA
76  
77 =head1 SOURCE AVAILABILITY
78  
79 This source is in Github:
80  
81 https://github.com/briandfoy/brick
82  
83 =head1 AUTHOR
84  
85 brian d foy, C<< <briandfoy@pobox.com> >>
86  
87 =head1 COPYRIGHT
88  
89 Copyright © 2007-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.
90  
91 You may redistribute this under the terms of the Artistic License 2.0.
92  
93 =cut
94  
95 5 1;
« Brick/Strings.pm ↑ Summary Brick/Numbers.pm »