| 1 | package Moose::Meta::TypeConstraint::Role; | ||||||||||||||||||||||||||||
| 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 B; | ||||||||||||||||||||||||||
|
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::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 398 | ▶ | use parent 'Moose::Meta::TypeConstraint'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 398 | __PACKAGE__->meta->add_attribute('role' => ( | |||||||||||||||||||||||||||
| 15 | reader => 'role', | ||||||||||||||||||||||||||||
| 16 | Class::MOP::_definition_context(), | ||||||||||||||||||||||||||||
| 17 | )); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2585 | ▶ | my $inliner = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2585 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 2585 | my $val = shift; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2585 | return 'Moose::Util::does_role(' | |||||||||||||||||||||||||||
| 24 | . $val . ', ' | ||||||||||||||||||||||||||||
| 25 | . B::perlstring($self->role) | ||||||||||||||||||||||||||||
| 26 | . ')'; | ||||||||||||||||||||||||||||
| 27 | 398 | }; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1289 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1289 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1289 | $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1289 | my $role_name = $args{role}; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1289 | $args{inlined} = $inliner; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1289 | my $self = $class->SUPER::new( \%args ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1289 | $self->compile_type_constraint(); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1289 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub parents { | ||||||||||||||||||||||||||
|
Subroutine
parents: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | return ( | ||||||||||||||||||||||||||||
| 49 | $self->parent, | ||||||||||||||||||||||||||||
| 50 | map { | ||||||||||||||||||||||||||||
| 51 | # FIXME find_type_constraint might find a TC named after the role but that isn't really it | ||||||||||||||||||||||||||||
| 52 | # I did this anyway since it's a convention that preceded TypeConstraint::Role, and it should DWIM | ||||||||||||||||||||||||||||
| 53 | # if anybody thinks this problematic please discuss on IRC. | ||||||||||||||||||||||||||||
| 54 | # a possible fix is to add by attr indexing to the type registry to find types of a certain property | ||||||||||||||||||||||||||||
| 55 | # regardless of their name | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | Moose::Util::TypeConstraints::find_type_constraint($_) | ||||||||||||||||||||||||||
|
Condition0%0/3
Moose::Util::TypeConstraints::find_type_constraint($_) || __PACKAGE__->new('role', $_, 'name', '__ANON__')
MC/DC0%0/2
Moose::Util::TypeConstraints::find_type_constraint($_) || __PACKAGE__->new('role', $_, 'name', '__ANON__')
Moose::Util::TypeConstraints::find_type_constraint($_)
__PACKAGE__->new('role', $_, 'name', '__ANON__')
Truth table0%0/3
A || B
A= Moose::Util::TypeConstraints::find_type_constraint($_)B= __PACKAGE__->new('role', $_, 'name', '__ANON__')
| |||||||||||||||||||||||||||||
| 57 | || | ||||||||||||||||||||||||||||
| 58 | __PACKAGE__->new( role => $_, name => "__ANON__" ) | ||||||||||||||||||||||||||||
| 59 | 0 | } @{ Class::MOP::class_of($self->role)->get_roles }, | |||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | ▶ | sub equals { | ||||||||||||||||||||||||||
|
Subroutine
equals: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 5 | my ( $self, $type_or_name ) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | return unless defined $other; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 4 | ▶ | return unless $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | return $self->role eq $other->role; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub is_a_type_of { | ||||||||||||||||||||||||||
|
Subroutine
is_a_type_of: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 1 | my ($self, $type_or_name) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | ($self->equals($type) || $self->is_subtype_of($type_or_name)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 7 | ▶ | sub is_subtype_of { | ||||||||||||||||||||||||||
|
Subroutine
is_subtype_of: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 7 | my ($self, $type_or_name_or_role ) = @_; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 7 | ▶ | if ( not ref $type_or_name_or_role ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | # it might be a role | ||||||||||||||||||||||||||||
| 87 | 6 | my $class = Class::MOP::class_of($self->role); | |||||||||||||||||||||||||||
| 88 | 6 | ▶ | return 1 if defined($class) && $class->does_role( $type_or_name_or_role ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $class and $class->does_role($type_or_name_or_role)
MC/DC100%2/2
defined $class and $class->does_role($type_or_name_or_role)
defined $class
$class->does_role($type_or_name_or_role)
Truth table100%3/3
A and B
A= defined $classB= $class->does_role($type_or_name_or_role)
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 5 | my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_role); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 5 | ▶ | return unless defined $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | ▶ | if ( $type->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | # if $type_or_name_or_role isn't a role, it might be the TC name of another ::Role type | ||||||||||||||||||||||||||||
| 97 | # or it could also just be a type object in this branch | ||||||||||||||||||||||||||||
| 98 | 2 | my $class = Class::MOP::class_of($self->role); | |||||||||||||||||||||||||||
| 99 | 2 | ▶ | return defined($class) && $class->does_role( $type->role ); | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $class && $class->does_role($type->role)
MC/DC50%1/2
defined $class && $class->does_role($type->role)
defined $class
$class->does_role($type->role)
Truth table66%2/3
A && B
A= defined $classB= $class->does_role($type->role)
| |||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||
| 101 | # the only other thing we are a subtype of is Object | ||||||||||||||||||||||||||||
| 102 | 1 | $self->SUPER::is_subtype_of($type); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub create_child_type { | ||||||||||||||||||||||||||
|
Subroutine
create_child_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 108 | 0 | return Moose::Meta::TypeConstraint->new(@args, parent => $self); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 398 | 1; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # ABSTRACT: Role/TypeConstraint parallel hierarchy | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||