blib/lib/Data/Rx/Type/PCRE.pm

filter: Statementstmt 83.3% 15 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 84.0% 21 / 25 CC 1 SCAR 1.7
CC
1
Cov
83%
type_uri
2.0
BEGIN
1.3
BEGIN
1.0
CRAP 1.2
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package Data::Rx::Type::PCRE;
5 {
6 $Data::Rx::Type::PCRE::VERSION = '0.005';
7 }
8 1 ▶use parent 'Data::Rx::CommonType::EasyNew';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: PCRE string checking for Rx (experimental)
11  
12 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 0 ▶sub type_uri { 'tag:rjbs.manxome.org,2008-10-04:rx/pcre/str' }
Subroutine type_uri: not called CC=1 SCAR=6.9
16  
17 sub guts_from_arg {
18 my ($class, $arg, $rx, $type) = @_;
19 $arg ||= {};
20  
21 my $regex = $arg->{regex};
22 my $flags = $arg->{flags} // '';
23  
24 Carp::croak("no regex supplied for $class type") unless defined $regex;
25  
26 my $regex_str = (length $flags) ? "(?$flags)$regex" : $regex;
27  
28 my $re = do {
29 0 ▶ use re::engine::PCRE;
Subroutine BEGIN: called CC=1 SCAR=2.6
30 qr{$regex_str};
31 };
32  
33 return {
34 re => $re,
35 re_str => $regex_str,
36 };
37 }
38  
39 sub assert_valid {
40 my ($self, $value) = @_;
41  
42 unless ($value =~ $self->{re}) {
43 $self->fail({
44 error => [ qw(value) ],
45 # we should pick better delimiters -- rjbs, 2012-09-18
46 message => "found value does not match /$self->{re_str}/",
47 value => $value,
48 });
49 }
50  
51 return 1;
52 }
53  
54 1;
55  
56 __END__
↑ Summary