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

filter: Statementstmt 94.1% 64 / 68 Branchbran 85.0% 17 / 20 Conditioncond 66.6% 6 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 93.7% 15 / 16 Podpod 100% 7 / 7 totaltotal 89.6% 113 / 126 CC 14 SCAR 12.5
CC
14
Cov
90%
is_subtype_of
7.0
parents
6.0
equals
4.2
CRAP 3.5
« blib/lib/Moose/Meta/Method/Accessor/Native/Collection.pm ↑ Summary blib/lib/Class/MOP/MiniTrait.pm »
1 package Moose::Meta::TypeConstraint::Class;
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 Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 398 ▶use Moose::Util::TypeConstraints ();
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('class' => (
15 reader => 'class',
16 Class::MOP::_definition_context(),
17 ));
18  
19 4529 ▶my $inliner = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 4529 my $self = shift;
21 4529 my $val = shift;
22  
23 4529 return 'Scalar::Util::blessed(' . $val . ')'
24 . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')';
25 398 };
26  
27 1758 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
28 1758 my ( $class, %args ) = @_;
29  
30 $args{parent}
31 1758 = Moose::Util::TypeConstraints::find_type_constraint('Object');
32  
33 1758 my $class_name = $args{class};
34 1758 ▶ $args{constraint} = sub { $_[0]->isa($class_name) };
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 1758 $args{inlined} = $inliner;
37  
38 1758 my $self = $class->SUPER::new( \%args );
39  
40 1758 $self->compile_type_constraint();
41  
42 1758 return $self;
43 }
44  
45 0 ▶sub parents {
Subroutine parents: not called CC=2 SCAR=17.9
Pod documented
46 0 my $self = shift;
47 return (
48 $self->parent,
49 map {
50 # FIXME find_type_constraint might find a TC named after the class but that isn't really it
51 # I did this anyway since it's a convention that preceded TypeConstraint::Class, and it should DWIM
52 # if anybody thinks this problematic please discuss on IRC.
53 # a possible fix is to add by attr indexing to the type registry to find types of a certain property
54 # regardless of their name
55 0 ▶ Moose::Util::TypeConstraints::find_type_constraint($_)
Condition0%0/3
Moose::Util::TypeConstraints::find_type_constraint($_) || __PACKAGE__->new('class', $_, 'name', '__ANON__')
l!l&&r!l&&!r
000
MC/DC0%0/2
Moose::Util::TypeConstraints::find_type_constraint($_) || __PACKAGE__->new('class', $_, 'name', '__ANON__')
Moose::Util::TypeConstraints::find_type_constraint($_) __PACKAGE__->new('class', $_, 'name', '__ANON__')
Truth table0%0/3
A || B
A= Moose::Util::TypeConstraints::find_type_constraint($_)B= __PACKAGE__->new('class', $_, 'name', '__ANON__')
ABresult
1X1
011
000
56 ||
57 __PACKAGE__->new( class => $_, name => "__ANON__" )
58 } Class::MOP::class_of($self->class)->superclasses,
59 );
60 }
61  
62 11 ▶sub equals {
Subroutine equals: called CC=4 SCAR=14.2
Pod documented
63 11 my ( $self, $type_or_name ) = @_;
64  
65 11 my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
66  
67 11 ▶ if (!defined($other)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $other) 4 7 11
68 4 ▶ if (!ref($type_or_name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type_or_name) 4 0 4
69 4 return $self->class eq $type_or_name;
70 }
71 0 return;
72 }
73  
74 7 ▶ return unless $other->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(__PACKAGE__) 0 7 7
75  
76 7 return $self->class eq $other->class;
77 }
78  
79 7 ▶sub is_a_type_of {
Subroutine is_a_type_of: called CC=2 SCAR=6.9
Pod documented
80 7 my ($self, $type_or_name) = @_;
81  
82 7 ▶ ($self->equals($type_or_name) || $self->is_subtype_of($type_or_name));
Branch: 1 branch
BranchTrueFalseTotal
$self->equals($type_or_name) or $self->is_subtype_of($type_or_name) 4 3 7
83 }
84  
85 18 ▶sub is_subtype_of {
Subroutine is_subtype_of: called CC=7 SCAR=19.5
Pod documented
86 18 my ($self, $type_or_name_or_class ) = @_;
87  
88 18 my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name_or_class);
89  
90 18 ▶ if ( not defined $type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 6 12 18
91 6 ▶ if ( not ref $type_or_name_or_class ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $type_or_name_or_class) 6 0 6
92 # it might be a class
93 6 my $class = $self->class;
94 6 ▶ return 1 if $class ne $type_or_name_or_class
Branch: 1 branch
BranchTrueFalseTotal
if $class ne $type_or_name_or_class and $class->isa($type_or_name_or_class) 2 4 6
Condition100%3/3
$class ne $type_or_name_or_class and $class->isa($type_or_name_or_class)
!ll&&!rl&&r
222
MC/DC100%2/2
$class ne $type_or_name_or_class and $class->isa($type_or_name_or_class)
$class ne $type_or_name_or_class $class->isa($type_or_name_or_class)
Truth table100%3/3
A and B
A= $class ne $type_or_name_or_classB= $class->isa($type_or_name_or_class)
ABresult
0X0
100
111
95 && $class->isa( $type_or_name_or_class );
96 }
97 4 return;
98 }
99  
100 12 ▶ if ( $type->isa(__PACKAGE__) && $type->class ne $self->class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type->isa(__PACKAGE__) and $type->class ne $self->class) { } 5 7 12
Condition100%3/3
$type->isa(__PACKAGE__) and $type->class ne $self->class
!ll&&!rl&&r
165
MC/DC100%2/2
$type->isa(__PACKAGE__) and $type->class ne $self->class
$type->isa(__PACKAGE__) $type->class ne $self->class
Truth table100%3/3
A and B
A= $type->isa(__PACKAGE__)B= $type->class ne $self->class
ABresult
0X0
100
111
101 # if $type_or_name_or_class isn't a class, it might be the TC name of another ::Class type
102 # or it could also just be a type object in this branch
103 5 return $self->class->isa( $type->class );
104 } else {
105 # the only other thing we are a subtype of is Object
106 7 $self->SUPER::is_subtype_of($type);
107 }
108 }
109  
110 # This is a bit counter-intuitive, but a child type of a Class type
111 # constraint is not itself a Class type constraint (it has no class
112 # attribute). This whole create_child_type thing needs some changing
113 # though, probably making MMC->new a factory or something.
114 12 ▶sub create_child_type {
Subroutine create_child_type: called CC=1 SCAR=0.0
Pod documented
115 12 my ($self, @args) = @_;
116 12 return Moose::Meta::TypeConstraint->new(@args, parent => $self);
117 }
118  
119 35 ▶sub get_message {
Subroutine get_message: called CC=3 SCAR=11.0
Pod documented
120 35 my $self = shift;
121 35 my ($value) = @_;
122  
123 35 ▶ if ($self->has_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_message) 2 33 35
124 2 return $self->SUPER::get_message(@_);
125 }
126  
127 33 ▶ $value = (defined $value ? overload::StrVal($value) : 'undef');
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 31 2 33
128 33 return "Validation failed for '" . $self->name . "' with value $value (not isa " . $self->class . ")";
129 }
130  
131 398 1;
132  
133 # ABSTRACT: Class/TypeConstraint parallel hierarchy
134  
135 __END__
« blib/lib/Moose/Meta/Method/Accessor/Native/Collection.pm ↑ Summary blib/lib/Class/MOP/MiniTrait.pm »