lib/Types/Standard/StrMatch.pm

filter: Statementstmt 100% 97 / 97 Branchbran 78.2% 36 / 46 Conditioncond 58.8% 10 / 17 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 20 / 20 Podpod n/a totaltotal 87.8% 167 / 190 CC 30 SCAR 15.4
CC
30
Cov
89%
_exporter_fail
10.1
__constraint_generator
6.2
__inline_generator
6.0
CRAP 4.7
« lib/Types/Standard/ScalarRef.pm ↑ Summary lib/Types/Standard/HashRef.pm »
1 # INTERNAL MODULE: guts for StrMatch type from Types::Standard.
2  
3 package Types::Standard::StrMatch;
4  
5 12 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 $Types::Standard::StrMatch::AUTHORITY = 'cpan:TOBYINK';
11 12 $Types::Standard::StrMatch::VERSION = '2.010001';
12 }
13  
14 12 $Types::Standard::StrMatch::VERSION =~ tr/_//d;
15  
16 12 ▶use Type::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use Types::Standard ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use Types::TypeTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
21  
22 12 ▶use Exporter::Tiny 1.004001 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 our @ISA = qw( Exporter::Tiny );
24  
25 2 ▶sub _exporter_fail {
Subroutine _exporter_fail: called CC=8 SCAR=23.1
26 2 my ( $class, $type_name, $values, $globals ) = @_;
27 2 my $caller = $globals->{into};
28
29 2 ▶ my $of = exists( $values->{of} ) ? $values->{of} : $values->{re};
Branch: 1 branch
BranchTrueFalseTotal
exists $values->{'of'} ? : 1 1 2
30 2 Types::Standard::RegexpRef->assert_valid( $of );
31
32 2 my $type = Types::Standard::StrMatch->of( $of );
33 $type = $type->create_child_type(
34 name => $type_name,
35 $type->has_coercion ? ( coercion => 1 ) : (),
36 2 ▶ exists( $values->{where} ) ? ( constraint => $values->{where} ) : (),
Branch: 2 branches
BranchTrueFalseTotal
$type->has_coercion ? : 0 2 2
exists $values->{'where'} ? : 0 2 2
37 );
38
39 $INC{'Type/Registry.pm'}
40 ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name )
41 : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type )
42 2 ▶ unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} );
Branch: 2 branches
BranchTrueFalseTotal
unless ref $caller or $caller eq "-lexical" or $globals->{"lexical"} 2 0 2
$INC{'Type/Registry.pm'} ? : 0 2 2
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
l!l&&r!l&&!r
002
ref $caller or $caller eq "-lexical"
l!l&&r!l&&!r
002
MC/DC0%0/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller $caller eq "-lexical" $globals->{"lexical"}
Truth table25%1/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
ABCresult
1XX1
01X1
0011
0000
43 2 return map +( $_->{name} => $_->{code} ), @{ $type->exportables };
44 }
45  
46 12 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 12 our %expressions;
49 12 my $has_regexp_util;
50 34 ▶my $serialize_regexp = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
51 34 ▶ $has_regexp_util = eval {
Branch: 1 branch
BranchTrueFalseTotal
unless defined $has_regexp_util 12 22 34
Condition50%1/2
eval { do { require Regexp::Util; 'Regexp::Util'->VERSION('0.003'); 1 } } || 0
l!l
120
MC/DC0%0/1
eval { do { require Regexp::Util; 'Regexp::Util'->VERSION('0.003'); 1 } } || 0
eval { do { require Regexp::Util; 'Regexp::Util'->VERSION('0.003'); 1 } }
Truth table50%1/2
A
A= eval { do { require Regexp::Util; 'Regexp::Util'->VERSION('0.003'); 1 } }
Aresult
11
00
52 12 require Regexp::Util;
53 12 Regexp::Util->VERSION( '0.003' );
54 12 1;
55 } || 0 unless defined $has_regexp_util;
56
57 34 my $re = shift;
58 34 my $serialized;
59 34 ▶ if ( $has_regexp_util ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_regexp_util) 34 0 34
60 34 $serialized = eval { Regexp::Util::serialize_regexp( $re ) };
61 }
62
63 34 ▶ unless ( defined $serialized ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $serialized) 4 30 34
64 4 my $key = sprintf( '%s|%s', ref( $re ), $re );
65 4 $expressions{$key} = $re;
66 4 $serialized = sprintf(
67 '$Types::Standard::StrMatch::expressions{%s}',
68 B::perlstring( $key )
69 );
70 }
71
72 34 return $serialized;
73 12 };
74  
75 36 ▶sub __constraint_generator {
Subroutine __constraint_generator: called CC=6 SCAR=18.2
76 36 ▶ return Types::Standard->meta->get_type( 'StrMatch' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 36 36
77
78 36 Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'StrMatch', \@_, 2, 1 );
79 36 my ( $regexp, $checker ) = @_;
80
81 36 ▶ Types::Standard::is_RegexpRef( $regexp )
Branch: 1 branch
BranchTrueFalseTotal
&Types::Standard::is_RegexpRef($regexp) or &_croak("First parameter to StrMatch[`a] expected to be a Regexp; got $regexp") 35 1 36
82 or _croak(
83 "First parameter to StrMatch[`a] expected to be a Regexp; got $regexp" );
84
85 35 ▶ if ( @_ > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 5 30 35
86 5 $checker = Types::TypeTiny::to_TypeTiny( $checker );
87 5 ▶ Types::TypeTiny::is_TypeTiny( $checker )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($checker) or &_croak("Second parameter to StrMatch[`a] expected to be a type constraint; got $checker") 4 1 5
88 or _croak(
89 "Second parameter to StrMatch[`a] expected to be a type constraint; got $checker"
90 );
91 }
92
93 $checker
94 24 ▶ ? sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
95 24 my $value = shift;
96 24 ▶ return if !defined ( $value );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 24 24
97 24 ▶ return if ref( $value );
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 24 24
98 24 my @m = ( $value =~ $regexp );
99 24 $checker->check( \@m );
100 }
101 30 ▶ : sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
102 30 my $value = shift;
103 30 ▶ defined( $value ) and !ref( $value ) and !!( $value =~ $regexp );
Branch: 1 branch
BranchTrueFalseTotal
defined $value and not ref $value and not !($value =~ /$regexp/) 30 0 30
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0030
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
104 34 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$checker ? : 4 30 34
105 } #/ sub __constraint_generator
106  
107 34 ▶sub __inline_generator {
Subroutine __inline_generator: called CC=6 SCAR=17.9
108 34 require B;
109 34 my ( $regexp, $checker ) = @_;
110 34 ▶ my $serialized_re = $regexp->$serialize_regexp or return;
Branch: 1 branch
BranchTrueFalseTotal
my $serialized_re = $regexp->$serialize_regexp or return 34 0 34
111
112 34 ▶ if ( $checker ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checker) { } 4 30 34
113 4 ▶ return unless $checker->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $checker->can_be_inlined 1 3 4
114
115 24 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
116 24 my $v = $_[1];
117 24 ▶ if ( $Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
if ($Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/) 1 23 24
Condition100%3/3
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
!ll&&!rl&&r
13101
MC/DC100%2/2
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
$Type::Tiny::AvoidCallbacks $serialized_re =~ /Types::Standard::StrMatch::expressions/
Truth table100%3/3
A and B
A= $Type::Tiny::AvoidCallbacksB= $serialized_re =~ /Types::Standard::StrMatch::expressions/
ABresult
0X0
100
111
118 and $serialized_re =~ /Types::Standard::StrMatch::expressions/ )
119 {
120 1 require Carp;
121 1 Carp::carp(
122 "Cannot serialize regexp without callbacks; serializing using callbacks" );
123 }
124 sprintf
125 24 "defined($v) and !ref($v) and do { my \$m = [$v =~ %s]; %s }",
126 $serialized_re,
127 $checker->inline_check( '$m' ),
128 ;
129 3 };
130 } #/ if ( $checker )
131 else {
132 30 my $regexp_string = "$regexp";
133 30 ▶ if ( $regexp_string =~ /\A\(\?\^u?:\\A(\.+)\)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexp_string =~ /\A\(\?\^u?:\\A(\.+)\)\z/) 1 29 30
134 1 my $length = length $1;
135 1 ▶ return sub { "defined($_) and !ref($_) and length($_)>=$length" };
Subroutine __ANON__: called CC=1 SCAR=0.0
136 }
137
138 29 ▶ if ( $regexp_string =~ /\A\(\?\^u?:\\A(\.+)\\z\)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexp_string =~ /\A\(\?\^u?:\\A(\.+)\\z\)\z/) 1 28 29
139 1 my $length = length $1;
140 1 ▶ return sub { "defined($_) and !ref($_) and length($_)==$length" };
Subroutine __ANON__: called CC=1 SCAR=0.0
141 }
142
143 177 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
144 177 my $v = $_[1];
145 177 ▶ if ( $Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
if ($Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/) 6 171 177
Condition100%3/3
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
!ll&&!rl&&r
141306
MC/DC100%2/2
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
$Type::Tiny::AvoidCallbacks $serialized_re =~ /Types::Standard::StrMatch::expressions/
Truth table100%3/3
A and B
A= $Type::Tiny::AvoidCallbacksB= $serialized_re =~ /Types::Standard::StrMatch::expressions/
ABresult
0X0
100
111
146 and $serialized_re =~ /Types::Standard::StrMatch::expressions/ )
147 {
148 6 require Carp;
149 6 Carp::carp(
150 "Cannot serialize regexp without callbacks; serializing using callbacks" );
151 }
152 177 "defined($v) and !ref($v) and !!( $v =~ $serialized_re )";
153 28 };
154 } #/ else [ if ( $checker ) ]
155 } #/ sub __inline_generator
156  
157 12 1;
158  
159 __END__
« lib/Types/Standard/ScalarRef.pm ↑ Summary lib/Types/Standard/HashRef.pm »