| 1 | package Type::Tiny::Enum; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 84 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 84 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 84 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 84 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 84 | $Type::Tiny::Enum::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 84 | $Type::Tiny::Enum::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 84 | $Type::Tiny::Enum::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 84 | ▶ | use Exporter::Tiny 1.004001 (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 84 | ▶ | use Type::Tiny (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 84 | our @ISA = qw( Type::Tiny Exporter::Tiny ); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | __PACKAGE__->_install_overloads( | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | q[@{}] => sub { shift->values }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 84 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub _exporter_fail { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_fail: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my ( $class, $type_name, $values, $globals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $caller = $globals->{into}; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my $type = $class->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | name => $type_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | values => [ @$values ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | coercion => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller or $caller eq "-lexical"
MC/DC33%1/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller
$caller eq "-lexical"
$globals->{"lexical"}
Truth table50%2/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | return map +( $_->{name} => $_->{code} ), @{ $type->exportables }; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 207 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 207 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | "Enum type constraints cannot have a parent constraint passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 207 | ▶ | if exists $opts{parent}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | "Enum type constraints cannot have a constraint coderef passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 206 | ▶ | if exists $opts{constraint}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | "Enum type constraints cannot have a sorter coderef passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 205 | ▶ | if exists $opts{sorter}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | "Enum type constraints cannot have a inlining coderef passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 205 | ▶ | if exists $opts{inlined}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 204 | ▶ | _croak "Need to supply list of values" unless exists $opts{values}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 84 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $opts{values} = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | map "$_", | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 203 | ▶ | @{ ref $opts{values} eq 'ARRAY' ? $opts{values} : [ $opts{values} ] } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 203 | my %tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 203 | undef $tmp{$_} for @{ $opts{values} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 203 | $opts{unique_values} = [ sort keys %tmp ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 203 | my $xs_encoding = _xs_encoding( $opts{unique_values} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 203 | ▶ | if ( defined $xs_encoding ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 197 | my $xsub = Type::Tiny::XS::get_coderef_for( $xs_encoding ); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 197 | ▶ | $opts{compiled_type_constraint} = $xsub if $xsub; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 203 | ▶ | if ( defined $opts{coercion} and !ref $opts{coercion} and 1 eq $opts{coercion} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $opts{"coercion"} and not ref $opts{"coercion"} and 1 eq $opts{"coercion"}
defined $opts{"coercion"} and not ref $opts{"coercion"}
MC/DC66%2/3
defined $opts{"coercion"} and not ref $opts{"coercion"} and 1 eq $opts{"coercion"}
defined $opts{"coercion"}
not ref $opts{"coercion"}
1 eq $opts{"coercion"}
Truth table75%3/4
A and not(B) and C
A= defined $opts{"coercion"}B= not ref $opts{"coercion"}C= 1 eq $opts{"coercion"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | delete $opts{coercion}; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | $opts{_build_coercion} = sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my $t = $c->type_constraint; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | $c->add_type_coercions( | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | Types::Standard::Str(), | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | ▶ | sub { $t->closest_match( @_ ? $_[0] : $_ ) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } #/ if ( defined $opts{coercion...}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 203 | return $proto->SUPER::new( %opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } #/ sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 203 | ▶ | sub _lockdown { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lockdown: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 203 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 203 | $callback->( $self->{values}, $self->{unique_values} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub new_union { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_union: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my @types = @{ delete $opts{type_constraints} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my @values = map @$_, @types; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $proto->new( %opts, values => \@values ); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub new_intersection { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_intersection: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my @types = @{ delete $opts{type_constraints} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | my %values; ++$values{$_} for map @$_, @types; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my @values = sort grep $values{$_}==@types, keys %values; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | $proto->new( %opts, values => \@values ); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 55 | ▶ | sub values { $_[0]{values} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 588 | ▶ | sub unique_values { $_[0]{unique_values} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unique_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 59 | ▶ | sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
constraint: called CC=2 SCAR=7.2
Pod
documented
Condition66%2/3
$_[0]{"constraint"} ||= $_[0]->_build_constraint
MC/DC0%0/2
$_[0]{"constraint"} ||= $_[0]->_build_constraint
$_[0]{"constraint"}
$_[0]->_build_constraint
Truth table66%2/3
A ||= B
A= $_[0]{"constraint"}B= $_[0]->_build_constraint
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 119 | ▶ | sub use_eq { return $_[0]{use_eq} if exists $_[0]{use_eq}; $_[0]{use_eq} = $_[0]->_build_use_eq } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
use_eq: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 123 | ▶ | sub _is_null_constraint { 0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_null_constraint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 21 | ▶ | sub _build_display_name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_display_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 21 | sprintf( "Enum[%s]", join q[,], @{ $self->unique_values } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 14 | ▶ | sub _build_use_eq { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_use_eq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | !Type::Tiny::_USE_XS and @{ $self->unique_values } <= 5; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | ▶ | sub is_word_safe { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_word_safe: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | return not grep /\W/, @{ $self->unique_values }; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | ▶ | sub exportables { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exportables: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | my ( $self, $base_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | ▶ | if ( not $self->is_anon ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | ▶ | $base_name ||= $self->name; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$base_name ||= $self->name
MC/DC0%0/2
$base_name ||= $self->name
$base_name
$self->name
Truth table33%1/3
A ||= B
A= $base_nameB= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | my $exportables = $self->SUPER::exportables( $base_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 8 | ▶ | if ( $self->is_word_safe ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | require Eval::TypeTiny; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | require B; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | for my $value ( @{ $self->unique_values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 22 | push @$exportables, { | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | name => uc( sprintf '%s_%s', $base_name, $value ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | tags => [ 'constants' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | code => Eval::TypeTiny::eval_closure( | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | source => sprintf( 'sub () { %s }', B::perlstring($value) ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | environment => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 8 | return $exportables; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 84 | my $new_xs; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Note the fallback code for older Type::Tiny::XS cannot be tested as | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # part of the coverage tests because they use the latest Type::Tiny::XS. | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 703 | ▶ | sub _xs_encoding { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xs_encoding: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 703 | my $unique_values = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 703 | return undef unless Type::Tiny::_USE_XS; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 639 | ▶ | return undef if @$unique_values > 50; # RT 121957 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 639 | ▶ | $new_xs = eval { Type::Tiny::XS->VERSION( "0.020" ); 1 } ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | unless defined $new_xs; | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 639 | ▶ | if ( $new_xs ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 639 | require B; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 639 | return sprintf( | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | "Enum[%s]", | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | join( ",", map B::perlstring( $_ ), @$unique_values ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | else { # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return undef if grep /\W/, @$unique_values; # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return sprintf( "Enum[%s]", join( ",", @$unique_values ) ); # uncoverable statement | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } #/ sub _xs_encoding | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 84 | my %cached; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 9 | ▶ | sub _build_constraint { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_constraint: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 9 | my $regexp = $self->_regexp; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | ▶ | return $cached{$regexp} if $cached{$regexp}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | my $coderef = ( $cached{$regexp} = sub { defined and m{\A(?:$regexp)\z} } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | Scalar::Util::weaken( $cached{$regexp} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | return $coderef; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 84 | my %cached; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | ▶ | sub _build_compiled_check { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_compiled_check: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | my $regexp = $self->_regexp; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | ▶ | return $cached{$regexp} if $cached{$regexp}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | my $coderef = ( $cached{$regexp} = $self->SUPER::_build_compiled_check( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | Scalar::Util::weaken( $cached{$regexp} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | return $coderef; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 84 | ▶ | sub _regexp { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regexp: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 105 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 105 | ▶ | $self->{_regexp} ||= 'Type::Tiny::Enum::_Trie'->handle( $self->unique_values ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_regexp"} ||= "Type::Tiny::Enum::_Trie"->handle($self->unique_values)
MC/DC0%0/2
$self->{"_regexp"} ||= "Type::Tiny::Enum::_Trie"->handle($self->unique_values)
$self->{"_regexp"}
"Type::Tiny::Enum::_Trie"->handle($self->unique_values)
Truth table66%2/3
A ||= B
A= $self->{"_regexp"}B= "Type::Tiny::Enum::_Trie"->handle($self->unique_values)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | sub as_regexp { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_regexp: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | my $flags = @_ ? $_[0] : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | ▶ | unless ( defined $flags and $flags =~ /^[i]*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $flags and $flags =~ /^[i]*$/
MC/DC50%1/2
defined $flags and $flags =~ /^[i]*$/
defined $flags
$flags =~ /^[i]*$/
Truth table66%2/3
A and B
A= defined $flagsB= $flags =~ /^[i]*$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | _croak( | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | "Unknown regexp flags: '$flags'; only 'i' currently accepted; stopped" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $regexp = $self->_regexp; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | $flags ? qr/\A(?:$regexp)\z/i : qr/\A(?:$regexp)\z/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } #/ sub as_regexp | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 435 | ▶ | sub can_be_inlined { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 435 | !!1; | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 500 | ▶ | sub inline_check { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inline_check: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 500 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 500 | ▶ | if ( my $xs_encoding = _xs_encoding( $self->unique_values ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 442 | my $xsub = Type::Tiny::XS::get_subname_for( $xs_encoding ); | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 442 | ▶ | return "$xsub\($_[0]\)" if $xsub && !$Type::Tiny::AvoidCallbacks; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$xsub and not $Type::Tiny::AvoidCallbacks
MC/DC50%1/2
$xsub and not $Type::Tiny::AvoidCallbacks
$xsub
not $Type::Tiny::AvoidCallbacks
Truth table66%2/3
A and not(B)
A= $xsubB= not $Type::Tiny::AvoidCallbacks
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 115 | my $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 115 | ▶ | if ( $self->use_eq ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 84 | ▶ | use B (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 27 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 27 | my @vals = grep { not $seen{$_}++ } @{ $self->values }; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 27 | ▶ | if ( @vals == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $code = sprintf( '(defined %s and !ref %s and %s eq %s)', $_[0], $_[0], $_[0], B::perlstring($vals[0]) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 27 | $code = sprintf( '(defined %s and !ref %s and (%s))', $_[0], $_[0], join q{ or } => map { sprintf '(%s eq %s)', $_[0], B::perlstring($_) } @vals ); | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 88 | my $regexp = $self->_regexp; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 88 | ▶ | $code = | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | $_[0] eq '$_' | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ? "(defined and !ref and m{\\A(?:$regexp)\\z})" | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | : "(defined($_[0]) and !ref($_[0]) and $_[0] =~ m{\\A(?:$regexp)\\z})"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 115 | ▶ | return "do { $Type::Tiny::SafePackage $code }" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | if $Type::Tiny::AvoidCallbacks; | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 34 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | } #/ sub inline_check | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub _instantiate_moose_type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_instantiate_moose_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | delete $opts{parent}; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | delete $opts{constraint}; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | delete $opts{inlined}; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | require Moose::Meta::TypeConstraint::Enum; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return "Moose::Meta::TypeConstraint::Enum" | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | ->new( %opts, values => $self->values ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } #/ sub _instantiate_moose_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 140 | ▶ | sub has_parent { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 140 | !!1; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 242 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 242 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 242 | Types::Standard::Str(); | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | ▶ | sub validate_explain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_explain: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | my ( $value, $varname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | $varname = '$_' unless defined $varname; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | ▶ | return undef if $self->check( $value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | !defined( $value ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ? [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | '"%s" requires that the value is defined', | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | : @$self < 13 ? [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | '"%s" requires that the value is equal to %s', | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | Type::Utils::english_list( \"or", map B::perlstring( $_ ), @$self ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | : [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | '"%s" requires that the value is one of an enumerated list of strings', | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } #/ sub validate_explain | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | ▶ | sub has_sorter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_sorter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | !!1; | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | ▶ | sub _enum_order_hash { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enum_order_hash: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | my %hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | for my $value ( @{ $self->values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 7 | ▶ | next if exists $hash{$value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 6 | $hash{$value} = $i++; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | return %hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | } #/ sub _enum_order_hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | ▶ | sub sorter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sorter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 2 | my %hash = $self->_enum_order_hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 15 | ▶ | sub { $_[0] <=> $_[1] }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 9 | ▶ | sub { exists( $hash{ $_[0] } ) ? $hash{ $_[0] } : 2_100_000_000 }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 84 | my $canon; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 9 | ▶ | sub closest_match { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
closest_match: called CC=15 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 9 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 9 | my ( $self, $given ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 9 | ▶ | return unless Types::Standard::is_Str $given; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 9 | ▶ | return $given if $self->check( $given ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 9 | ▶ | $canon ||= eval( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$canon ||= eval($] lt "5.016" ? " sub { ( my \$var = lc(\$_[0]) ) =~ s/(^\\s+)|(\\s+\$)//g; \$var } " : " sub { CORE::fc(\$_[0]) =~ s/(^\\s+)|(\\s+\$)//gr; } ")
MC/DC0%0/2
$canon ||= eval($] lt "5.016" ? " sub { ( my \$var = lc(\$_[0]) ) =~ s/(^\\s+)|(\\s+\$)//g; \$var } " : " sub { CORE::fc(\$_[0]) =~ s/(^\\s+)|(\\s+\$)//gr; } ")
$canon
eval($] lt "5.016" ? " sub { ( my \$var = lc(\$_[0]) ) =~ s/(^\\s+)|(\\s+\$)//g; \$var } " : " sub { CORE::fc(\$_[0]) =~ s/(^\\s+)|(\\s+\$)//gr; } ")
Truth table66%2/3
A ||= B
A= $canonB= eval($] lt "5.016" ? " sub { ( my \$var = lc(\$_[0]) ) =~ s/(^\\s+)|(\\s+\$)//g; \$var } " : " sub { CORE::fc(\$_[0]) =~ s/(^\\s+)|(\\s+\$)//gr; } ")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | $] lt '5.016' | ||||||||||||||||||||||||||||||||||||||||||||||
| 360 | ? q< sub { ( my $var = lc($_[0]) ) =~ s/(^\s+)|(\s+$)//g; $var } > | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | : q< sub { CORE::fc($_[0]) =~ s/(^\s+)|(\s+$)//gr; } > | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 9 | ▶ | $self->{_lookups} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_lookups"} ||= do {
my %lookups;
foreach $_ (@{$self->values;}) {
my $key = &$canon($_);
next if exists $lookups{$key};
$lookups{$key} = $_;
};
\%lookups
}
MC/DC0%0/2
$self->{"_lookups"} ||= do {
my %lookups;
foreach $_ (@{$self->values;}) {
my $key = &$canon($_);
next if exists $lookups{$key};
$lookups{$key} = $_;
};
\%lookups
}
$self->{"_lookups"}
do {
my %lookups;
foreach $_ (@{$self->values;}) {
my $key = &$canon($_);
next if exists $lookups{$key};
$lookups{$key} = $_;
};
\%lookups
}
Truth table66%2/3
A ||= B
A= $self->{"_lookups"}B= do {
my %lookups;
foreach $_ (@{$self->values;}) {
my $key = &$canon($_);
next if exists $lookups{$key};
$lookups{$key} = $_;
};
\%lookups
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | my %lookups; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | for ( @{ $self->values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 3 | my $key = $canon->( $_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | ▶ | next if exists $lookups{$key}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | $lookups{$key} = $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | \%lookups; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 9 | my $cgiven = $canon->( $given ); | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | return $self->{_lookups}{$cgiven} | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 9 | ▶ | if $self->{_lookups}{$cgiven}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 7 | my $best; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7 | VALUE: for my $possible ( @{ $self->values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 21 | my $stem = substr( $possible, 0, length $cgiven ); | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 21 | ▶ | if ( $cgiven eq $canon->( $stem ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 3 | ▶ | if ( defined( $best ) and length( $best ) >= length( $possible ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $best and length $best >= length $possible
MC/DC50%1/2
defined $best and length $best >= length $possible
defined $best
length $best >= length $possible
Truth table66%2/3
A and B
A= defined $bestB= length $best >= length $possible
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | next VALUE; | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 2 | $best = $possible; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 7 | ▶ | return $best if defined $best; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 5 | ▶ | return $self->values->[$given] | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | if Types::Standard::is_Int $given; | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | return $given; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | } #/ sub closest_match | ||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 88 | ▶ | push @Type::Tiny::CMP, sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 88 | my $A = shift->find_constraining_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | 88 | my $B = shift->find_constraining_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | 88 | ▶ | return Type::Tiny::CMP_UNKNOWN | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$A->isa(__PACKAGE__) and $B->isa(__PACKAGE__)
MC/DC100%2/2
$A->isa(__PACKAGE__) and $B->isa(__PACKAGE__)
$A->isa(__PACKAGE__)
$B->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= $A->isa(__PACKAGE__)B= $B->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | unless $A->isa( __PACKAGE__ ) && $B->isa( __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 14 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 14 | for my $word ( @{ $A->unique_values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | 72 | $seen{$word} += 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 14 | for my $word ( @{ $B->unique_values } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 408 | 72 | $seen{$word} += 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 14 | my $values = join( '', CORE::values %seen ); | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | 14 | ▶ | if ( $values =~ /^3*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | return Type::Tiny::CMP_EQUIVALENT; | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif ( $values !~ /2/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | return Type::Tiny::CMP_SUPERTYPE; | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | elsif ( $values !~ /1/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3 | return Type::Tiny::CMP_SUBTYPE; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 8 | return Type::Tiny::CMP_UNKNOWN; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 84 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||
| 425 | package # stolen from Regexp::Trie | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | Type::Tiny::Enum::_Trie; | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 16 | ▶ | sub new { bless {} => shift } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 144 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 144 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 431 | 144 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | 144 | my $ref = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 144 | for my $char ( split //, $str ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1041 | ▶ | $ref->{$char} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ref->{$char} ||= {}
MC/DC100%1/1
$ref->{$char} ||= {}
$ref->{$char}
Truth table100%2/2
A
A= $ref->{$char}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 1041 | $ref = $ref->{$char}; | |||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 144 | $ref->{''} = 1; # { '' => 1 } as terminator | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 144 | $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | } #/ sub add | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 897 | ▶ | sub _regexp { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_regexp: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 897 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | 897 | ▶ | return if $self->{''} and scalar keys %$self == 1; # terminator | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{""} and scalar keys %$self == 1
MC/DC100%2/2
$self->{""} and scalar keys %$self == 1
$self->{""}
scalar keys %$self == 1
Truth table100%3/3
A and B
A= $self->{""}B= scalar keys %$self == 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 761 | my ( @alt, @cc ); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 761 | my $q = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 761 | for my $char ( sort keys %$self ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | 889 | my $qchar = quotemeta $char; | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 889 | ▶ | if ( ref $self->{$char} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 881 | ▶ | if ( defined( my $recurse = _regexp( $self->{$char} ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 745 | push @alt, $qchar . $recurse; | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 136 | push @cc, $qchar; | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 8 | $q = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } #/ for my $char ( sort keys...) | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 761 | my $cconly = !@alt; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 761 | ▶ | @cc and push @alt, @cc == 1 ? $cc[0] : '[' . join( '', @cc ) . ']'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 761 | ▶ | my $result = @alt == 1 ? $alt[0] : '(?:' . join( '|', @alt ) . ')'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 761 | ▶ | $q and $result = $cconly ? "$result?" : "(?:$result)?"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 761 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | } #/ sub _regexp | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 16 | ▶ | sub handle { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 16 | my ( $vals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | 16 | ▶ | return '(?!)' unless @$vals; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 16 | my $self = $class->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | 16 | $self->add( $_ ) for @$vals; | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | 16 | $self->_regexp; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 84 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||