blib/lib/Moose/Meta/TypeConstraint/Role.pm

filter: Statementstmt 88.5% 54 / 61 Branchbran 85.7% 12 / 14 Conditioncond 55.5% 5 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 80.0% 12 / 15 Podpod 100% 6 / 6 totaltotal 82.8% 92 / 111 CC 11 SCAR 12.4
CC
11
Cov
85%
is_subtype_of
7.0
parents
6.0
equals
3.0
CRAP 3.5
« blib/lib/Class/MOP/MiniTrait.pm ↑ Summary blib/lib/Class/MOP/Package.pm »
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__')
l!l&&r!l&&!r
000
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__')
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless defined $other 1 4 5
69 4 ▶ return unless $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 4 4
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
BranchTrueFalseTotal
$self->equals($type) or $self->is_subtype_of($type_or_name) 0 1 1
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
BranchTrueFalseTotal
unless (ref $type_or_name_or_role) 6 1 7
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
BranchTrueFalseTotal
if defined $class and $class->does_role($type_or_name_or_role) 2 4 6
Condition100%3/3
defined $class and $class->does_role($type_or_name_or_role)
!ll&&!rl&&r
132
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $type 2 3 5
94  
95 3 ▶ if ( $type->isa(__PACKAGE__) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->isa(__PACKAGE__)) { } 2 1 3
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)
!ll&&!rl&&r
101
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)
ABresult
0X0
100
111
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__
« blib/lib/Class/MOP/MiniTrait.pm ↑ Summary blib/lib/Class/MOP/Package.pm »