| 1 | package Type::Tiny::Intersection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 20 | $Type::Tiny::Intersection::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 9 | 20 | $Type::Tiny::Intersection::VERSION = '2.010001'; | |||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 20 | $Type::Tiny::Intersection::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use Scalar::Util qw< blessed >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 20 | ▶ | use Types::TypeTiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 20 | ▶ | use Type::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 20 | our @ISA = 'Type::Tiny'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | __PACKAGE__->_install_overloads( | ||||||||||||||||||||||||||||
| 23 | 342 | ▶ | q[@{}] => sub { $_[0]{type_constraints} ||= [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]{"type_constraints"} ||= []
MC/DC0%0/1
$_[0]{"type_constraints"} ||= []
$_[0]{"type_constraints"}
Truth table50%1/2
A
A= $_[0]{"type_constraints"}
| |||||||||||||||||||||||||||||
| 24 | 20 | ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 40068 | ▶ | sub new_by_overload { | ||||||||||||||||||||||||||
|
Subroutine
new_by_overload: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 40068 | my $proto = shift; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 40068 | my @types = @{ $opts{type_constraints} }; | |||||||||||||||||||||||||||
| 31 | 40068 | ▶ | if ( my @makers = map scalar( blessed($_) && $_->can( 'new_intersection' ) ), @types ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($_) && $_->can('new_intersection')
MC/DC100%2/2
builtin::blessed($_) && $_->can('new_intersection')
builtin::blessed($_)
$_->can('new_intersection')
Truth table100%3/3
A && B
A= builtin::blessed($_)B= $_->can('new_intersection')
| |||||||||||||||||||||||||||||
| 32 | 40068 | my $first_maker = shift @makers; | |||||||||||||||||||||||||||
| 33 | 40068 | ▶ | if ( ref $first_maker ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | my $all_same = not grep $_ ne $first_maker, @makers; | |||||||||||||||||||||||||||
| 35 | 2 | ▶ | if ( $all_same ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 2 | return ref( $types[0] )->$first_maker( %opts ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 40066 | return $proto->new( \%opts ); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 40090 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 40090 | my $proto = shift; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 40090 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | _croak "Intersection type constraints cannot have a parent constraint" | ||||||||||||||||||||||||||||
| 49 | 40090 | ▶ | if exists $opts{parent}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | _croak | ||||||||||||||||||||||||||||
| 51 | "Intersection type constraints cannot have a constraint coderef passed to the constructor" | ||||||||||||||||||||||||||||
| 52 | 40089 | ▶ | if exists $opts{constraint}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | _croak | ||||||||||||||||||||||||||||
| 54 | "Intersection type constraints cannot have a inlining coderef passed to the constructor" | ||||||||||||||||||||||||||||
| 55 | 40088 | ▶ | if exists $opts{inlined}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | _croak "Need to supply list of type constraints" | ||||||||||||||||||||||||||||
| 57 | 40087 | ▶ | unless exists $opts{type_constraints}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | $opts{type_constraints} = [ | ||||||||||||||||||||||||||||
| 60 | 80183 | ▶ | map { $_->isa( __PACKAGE__ ) ? @$_ : $_ } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | map Types::TypeTiny::to_TypeTiny( $_ ), | ||||||||||||||||||||||||||||
| 62 | @{ | ||||||||||||||||||||||||||||
| 63 | 40086 | ref $opts{type_constraints} eq "ARRAY" | |||||||||||||||||||||||||||
| 64 | ? $opts{type_constraints} | ||||||||||||||||||||||||||||
| 65 | 40086 | ▶ | : [ $opts{type_constraints} ] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | ]; | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 40086 | if ( Type::Tiny::_USE_XS ) { | |||||||||||||||||||||||||||
| 70 | 40086 | my @constraints = @{ $opts{type_constraints} }; | |||||||||||||||||||||||||||
| 71 | my @known = map { | ||||||||||||||||||||||||||||
| 72 | 40086 | my $known = Type::Tiny::XS::is_known( $_->compiled_check ); | |||||||||||||||||||||||||||
| 73 | 80207 | ▶ | defined( $known ) ? $known : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } @constraints; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 40086 | ▶ | if ( @known == @constraints ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 17 | my $xsub = Type::Tiny::XS::get_coderef_for( | |||||||||||||||||||||||||||
| 78 | sprintf "AllOf[%s]", | ||||||||||||||||||||||||||||
| 79 | join( ',', @known ) | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | 17 | ▶ | $opts{compiled_type_constraint} = $xsub if $xsub; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } #/ if ( Type::Tiny::_USE_XS) | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 40086 | return $proto->SUPER::new( %opts ); | |||||||||||||||||||||||||||
| 86 | } #/ sub new | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 40086 | ▶ | sub _lockdown { | ||||||||||||||||||||||||||
|
Subroutine
_lockdown: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 40086 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||
| 90 | 40086 | $callback->( $self->{type_constraints} ); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 44 | ▶ | sub type_constraints { $_[0]{type_constraints} } | ||||||||||||||||||||||||||
|
Subroutine
type_constraints: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 55 | ▶ | 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
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 110 | ▶ | sub _is_null_constraint { 0 } | ||||||||||||||||||||||||||
|
Subroutine
_is_null_constraint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 41 | ▶ | sub _build_display_name { | ||||||||||||||||||||||||||
|
Subroutine
_build_display_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 41 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 41 | join q[&], @$self; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 26 | ▶ | sub _build_constraint { | ||||||||||||||||||||||||||
|
Subroutine
_build_constraint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 26 | my @checks = map $_->compiled_check, @{ +shift }; | |||||||||||||||||||||||||||
| 105 | 68 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 106 | 68 | my $val = $_; | |||||||||||||||||||||||||||
| 107 | 68 | ▶ | $_->( $val ) || return for @checks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 47 | return !!1; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 26 | } | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 119 | ▶ | sub can_be_inlined { | ||||||||||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 119 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 119 | not grep !$_->can_be_inlined, @$self; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 114 | ▶ | sub inline_check { | ||||||||||||||||||||||||||
|
Subroutine
inline_check: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 114 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 114 | ▶ | if ( Type::Tiny::_USE_XS and !exists $self->{xs_sub} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 34 | $self->{xs_sub} = undef; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 34 | my @constraints = @{ $self->type_constraints }; | |||||||||||||||||||||||||||
| 124 | my @known = map { | ||||||||||||||||||||||||||||
| 125 | 34 | my $known = Type::Tiny::XS::is_known( $_->compiled_check ); | |||||||||||||||||||||||||||
| 126 | 71 | ▶ | defined( $known ) ? $known : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | } @constraints; | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 34 | ▶ | if ( @known == @constraints ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 7 | $self->{xs_sub} = Type::Tiny::XS::get_subname_for( | |||||||||||||||||||||||||||
| 131 | sprintf "AllOf[%s]", | ||||||||||||||||||||||||||||
| 132 | join( ',', @known ) | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } #/ if ( Type::Tiny::_USE_XS...) | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 114 | my $code = sprintf '(%s)', join " and ", map $_->inline_check( $_[0] ), @$self; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 114 | ▶ | return "do { $Type::Tiny::SafePackage $code }" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | if $Type::Tiny::AvoidCallbacks; | ||||||||||||||||||||||||||||
| 141 | return "$self->{xs_sub}\($_[0]\)" | ||||||||||||||||||||||||||||
| 142 | 94 | ▶ | if $self->{xs_sub}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 80 | return $code; | |||||||||||||||||||||||||||
| 144 | } #/ sub inline_check | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 71 | ▶ | sub has_parent { | ||||||||||||||||||||||||||
|
Subroutine
has_parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 71 | !!@{ $_[0]{type_constraints} }; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 111 | ▶ | sub parent { | ||||||||||||||||||||||||||
|
Subroutine
parent: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 111 | $_[0]{type_constraints}[0]; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | ▶ | sub validate_explain { | ||||||||||||||||||||||||||
|
Subroutine
validate_explain: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 156 | 1 | my ( $value, $varname ) = @_; | |||||||||||||||||||||||||||
| 157 | 1 | ▶ | $varname = '$_' unless defined $varname; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 1 | ▶ | return undef if $self->check( $value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1 | require Type::Utils; | |||||||||||||||||||||||||||
| 162 | 1 | for my $type ( @$self ) { | |||||||||||||||||||||||||||
| 163 | 1 | my $deep = $type->validate_explain( $value, $varname ); | |||||||||||||||||||||||||||
| 164 | return [ | ||||||||||||||||||||||||||||
| 165 | 1 | ▶ | sprintf( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | '"%s" requires that the value pass %s', | ||||||||||||||||||||||||||||
| 167 | $self, | ||||||||||||||||||||||||||||
| 168 | Type::Utils::english_list( map qq["$_"], @$self ), | ||||||||||||||||||||||||||||
| 169 | ), | ||||||||||||||||||||||||||||
| 170 | @$deep, | ||||||||||||||||||||||||||||
| 171 | ] if $deep; | ||||||||||||||||||||||||||||
| 172 | } #/ for my $type ( @$self ) | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # This should never happen... | ||||||||||||||||||||||||||||
| 175 | 0 | return; # uncoverable statement | |||||||||||||||||||||||||||
| 176 | } #/ sub validate_explain | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 5 | ▶ | my $_delegate = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 179 | 5 | my ( $self, $method ) = ( shift, shift ); | |||||||||||||||||||||||||||
| 180 | 5 | my @types = @{ $self->type_constraints }; | |||||||||||||||||||||||||||
| 181 | 5 | my $found = 0; | |||||||||||||||||||||||||||
| 182 | 5 | for my $i ( 0 .. $#types ) { | |||||||||||||||||||||||||||
| 183 | 9 | my $type = $types[$i]; | |||||||||||||||||||||||||||
| 184 | 9 | ▶ | if ( $type->can( $method ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 5 | $types[$i] = $type->$method( @_ ); | |||||||||||||||||||||||||||
| 186 | 5 | ++$found; | |||||||||||||||||||||||||||
| 187 | 5 | last; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | _croak( | ||||||||||||||||||||||||||||
| 191 | 5 | ▶ | 'Could not apply method %s to any type within the intersection', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | $method | ||||||||||||||||||||||||||||
| 193 | ) unless $found; | ||||||||||||||||||||||||||||
| 194 | 5 | ref( $self )->new( type_constraints => \@types ); | |||||||||||||||||||||||||||
| 195 | 20 | }; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 1 | ▶ | sub stringifies_to { | ||||||||||||||||||||||||||
|
Subroutine
stringifies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 199 | 1 | $self->$_delegate( stringifies_to => @_ ); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | sub numifies_to { | ||||||||||||||||||||||||||
|
Subroutine
numifies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 204 | 2 | $self->$_delegate( numifies_to => @_ ); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 2 | ▶ | sub with_attribute_values { | ||||||||||||||||||||||||||
|
Subroutine
with_attribute_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 209 | 2 | $self->$_delegate( with_attribute_values => @_ ); | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 20 | my $comparator; | |||||||||||||||||||||||||||
| 213 | 99 | ▶ | $comparator = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 214 | 99 | my $A = shift->find_constraining_type; | |||||||||||||||||||||||||||
| 215 | 99 | my $B = shift->find_constraining_type; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 99 | ▶ | if ( $A->isa( __PACKAGE__ ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 218 | 3 | my @A_constraints = map $_->find_constraining_type, @{ $A->type_constraints }; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 3 | my @A_equal_to_B = grep $_->equals( $B ), @A_constraints; | |||||||||||||||||||||||||||
| 221 | 3 | ▶ | if ( @A_equal_to_B == @A_constraints ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | return Type::Tiny::CMP_EQUIVALENT(); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 3 | my @A_subs_of_B = grep $_->is_a_type_of( $B ), @A_constraints; | |||||||||||||||||||||||||||
| 226 | 3 | ▶ | if ( @A_subs_of_B ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 2 | return Type::Tiny::CMP_SUBTYPE(); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | } #/ if ( $A->isa( __PACKAGE__...)) | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | elsif ( $B->isa( __PACKAGE__ ) ) { | ||||||||||||||||||||||||||||
| 232 | 1 | my $r = $comparator->( $B, $A ); | |||||||||||||||||||||||||||
| 233 | 1 | ▶ | return $r if $r eq Type::Tiny::CMP_EQUIVALENT(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 1 | ▶ | return -$r if $r eq Type::Tiny::CMP_SUBTYPE(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 97 | return Type::Tiny::CMP_UNKNOWN(); | |||||||||||||||||||||||||||
| 238 | 20 | }; | |||||||||||||||||||||||||||
| 239 | 20 | push @Type::Tiny::CMP, $comparator; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 20 | 1; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||