| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller or $caller eq "-lexical"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
eval {
do {
require Regexp::Util;
'Regexp::Util'->VERSION('0.003');
1
}
} || 0
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
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 34 | $serialized = eval { Regexp::Util::serialize_regexp( $re ) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 34 | ▶ | unless ( defined $serialized ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | or _croak( | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | "First parameter to StrMatch[`a] expected to be a Regexp; got $regexp" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 35 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | $checker = Types::TypeTiny::to_TypeTiny( $checker ); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 5 | ▶ | Types::TypeTiny::is_TypeTiny( $checker ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | ▶ | return if ref( $value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $value and not ref $value
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 34 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 34 | ▶ | if ( $checker ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | return unless $checker->can_be_inlined; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$Type::Tiny::AvoidCallbacks and $serialized_re =~ /Types::Standard::StrMatch::expressions/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||