| 1 | package Moose::Meta::TypeConstraint::Parameterized; | ||||||||||||||||||||||||||||||||||
| 2 | 398 | our $VERSION = '2.4001'; | |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 398 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 398 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 398 | ▶ | use metaclass; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 398 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 398 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 398 | ▶ | use Moose::Meta::TypeConstraint::Parameterizable; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 398 | ▶ | use Moose::Util 'throw_exception'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 398 | ▶ | use parent 'Moose::Meta::TypeConstraint'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 398 | __PACKAGE__->meta->add_attribute('type_parameter' => ( | |||||||||||||||||||||||||||||||||
| 16 | accessor => 'type_parameter', | ||||||||||||||||||||||||||||||||||
| 17 | predicate => 'has_type_parameter', | ||||||||||||||||||||||||||||||||||
| 18 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||||||||
| 19 | )); | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 398 | __PACKAGE__->meta->add_attribute('parameterized_from' => ( | |||||||||||||||||||||||||||||||||
| 22 | accessor => 'parameterized_from', | ||||||||||||||||||||||||||||||||||
| 23 | predicate => 'has_parameterized_from', | ||||||||||||||||||||||||||||||||||
| 24 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||||||||
| 25 | )); | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 132 | ▶ | sub equals { | ||||||||||||||||||||||||||||||||
|
Subroutine
equals: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 28 | 132 | my ( $self, $type_or_name ) = @_; | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 132 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 132 | ▶ | return unless $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | return ( | ||||||||||||||||||||||||||||||||||
| 35 | 8 | ▶ | $self->type_parameter->equals( $other->type_parameter ) | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->type_parameter->equals($other->type_parameter) && $self->parent->equals($other->parent)
MC/DC50%1/2
$self->type_parameter->equals($other->type_parameter) && $self->parent->equals($other->parent)
$self->type_parameter->equals($other->type_parameter)
$self->parent->equals($other->parent)
Truth table66%2/3
A && B
A= $self->type_parameter->equals($other->type_parameter)B= $self->parent->equals($other->parent)
| |||||||||||||||||||||||||||||||||||
| 36 | and | ||||||||||||||||||||||||||||||||||
| 37 | $self->parent->equals( $other->parent ) | ||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 147 | ▶ | sub compile_type_constraint { | ||||||||||||||||||||||||||||||||
|
Subroutine
compile_type_constraint: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 42 | 147 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 147 | ▶ | unless ( $self->has_type_parameter ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 1 | throw_exception( CannotCreateHigherOrderTypeWithoutATypeParameter => type_name => $self->name ); | |||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | 146 | my $type_parameter = $self->type_parameter; | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 146 | ▶ | unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($type_parameter) and $type_parameter->isa("Moose::Meta::TypeConstraint")
MC/DC50%1/2
builtin::blessed($type_parameter) and $type_parameter->isa("Moose::Meta::TypeConstraint")
builtin::blessed($type_parameter)
$type_parameter->isa("Moose::Meta::TypeConstraint")
Truth table66%2/3
A and B
A= builtin::blessed($type_parameter)B= $type_parameter->isa("Moose::Meta::TypeConstraint")
| |||||||||||||||||||||||||||||||||||
| 51 | 1 | throw_exception( TypeParameterMustBeMooseMetaType => type_name => $self->name ); | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 145 | foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) { | |||||||||||||||||||||||||||||||||
| 55 | 341 | ▶ | if (my $constraint = $type->generate_constraint_for($self)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 142 | $self->_set_constraint($constraint); | |||||||||||||||||||||||||||||||||
| 57 | 142 | return $self->SUPER::compile_type_constraint; | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | # if we get here, then we couldn't | ||||||||||||||||||||||||||||||||||
| 62 | # find a way to parameterize this type | ||||||||||||||||||||||||||||||||||
| 63 | 3 | throw_exception( TypeConstraintCannotBeUsedForAParameterizableType => type_name => $self->name, | |||||||||||||||||||||||||||||||||
| 64 | parent_type_name => $self->parent->name, | ||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 1199 | ▶ | sub can_be_inlined { | ||||||||||||||||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 69 | 1199 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | return | ||||||||||||||||||||||||||||||||||
| 72 | 1199 | ▶ | $self->has_parameterized_from | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$self->has_parameterized_from && $self->parameterized_from->has_inline_generator && $self->type_parameter->can_be_inlined
$self->has_parameterized_from and $self->parameterized_from->has_inline_generator
MC/DC100%3/3
$self->has_parameterized_from && $self->parameterized_from->has_inline_generator && $self->type_parameter->can_be_inlined
$self->has_parameterized_from
$self->parameterized_from->has_inline_generator
$self->type_parameter->can_be_inlined
Truth table100%4/4
A and B && C
A= $self->has_parameterized_fromB= $self->parameterized_from->has_inline_generatorC= $self->type_parameter->can_be_inlined
| |||||||||||||||||||||||||||||||||||
| 73 | && $self->parameterized_from->has_inline_generator | ||||||||||||||||||||||||||||||||||
| 74 | && $self->type_parameter->can_be_inlined; | ||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 614 | ▶ | sub inline_environment { | ||||||||||||||||||||||||||||||||
|
Subroutine
inline_environment: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 78 | 614 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | return { | ||||||||||||||||||||||||||||||||||
| 81 | ($self->has_parameterized_from | ||||||||||||||||||||||||||||||||||
| 82 | 613 | ▶ | ? (%{ $self->parameterized_from->inline_environment }) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | : ()), | ||||||||||||||||||||||||||||||||||
| 84 | ($self->has_type_parameter | ||||||||||||||||||||||||||||||||||
| 85 | 614 | ▶ | ? (%{ $self->type_parameter->inline_environment }) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 86 | : ()), | ||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 336 | ▶ | sub _inline_check { | ||||||||||||||||||||||||||||||||
|
Subroutine
_inline_check: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 91 | 336 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 336 | ▶ | return unless $self->can_be_inlined; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 336 | return $self->parameterized_from->generate_inline_for( $self->type_parameter, @_ ); | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 27 | ▶ | sub create_child_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
create_child_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 99 | 27 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||
| 100 | 27 | return Moose::Meta::TypeConstraint::Parameterizable->new(%opts, parent=>$self); | |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 398 | 1; | |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | # ABSTRACT: Type constraints with a bound parameter (ArrayRef[Int]) | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||||||||