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

filter: Statementstmt 89.7% 35 / 39 Branchbran 50.0% 5 / 10 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 5 / 5 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 87.5% 70 / 80 CC 9 SCAR 13.0
CC
9
Cov
84%
find_type_constraint
12.0
add_type_constraint
4.0
has_type_constraint
3.0
CRAP 3.7
« blib/lib/oose.pm ↑ Summary blib/lib/Moose/Util/MetaRole.pm »
1 package Moose::Meta::TypeConstraint::Registry;
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  
10 398 ▶use parent 'Class::MOP::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 398 ▶use Moose::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 398 __PACKAGE__->meta->add_attribute('parent_registry' => (
15 reader => 'get_parent_registry',
16 writer => 'set_parent_registry',
17 predicate => 'has_parent_registry',
18 Class::MOP::_definition_context(),
19 ));
20  
21 __PACKAGE__->meta->add_attribute('type_constraints' => (
22 reader => 'type_constraints',
23 399 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 398 Class::MOP::_definition_context(),
25 ));
26  
27 399 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
28 399 my $class = shift;
29 399 my $self = $class->_new(@_);
30 399 return $self;
31 }
32  
33 18243 ▶sub has_type_constraint {
Subroutine has_type_constraint: called CC=3 SCAR=11.0
Pod documented
34 18243 my ($self, $type_name) = @_;
35 18243 ▶ ($type_name and exists $self->type_constraints->{$type_name}) ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$type_name && exists $self->type_constraints->{$type_name} ? : 15001 3242 18243
Condition100%3/3
$type_name and exists $self->type_constraints->{$type_name}
!ll&&!rl&&r
2324015001
MC/DC100%2/2
$type_name and exists $self->type_constraints->{$type_name}
$type_name exists $self->type_constraints->{$type_name}
Truth table100%3/3
A and B
A= $type_nameB= exists $self->type_constraints->{$type_name}
ABresult
0X0
100
111
36 }
37  
38 26643 ▶sub get_type_constraint {
Subroutine get_type_constraint: called CC=2 SCAR=7.1
Pod documented
39 26643 my ($self, $type_name) = @_;
40 26643 ▶ return unless defined $type_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type_name 0 26643 26643
41 26643 $self->type_constraints->{$type_name}
42 }
43  
44 11736 ▶sub add_type_constraint {
Subroutine add_type_constraint: called CC=4 SCAR=13.9
Pod documented
45 11736 my ($self, $type) = @_;
46  
47 11736 ▶ unless ( $type && blessed $type && $type->isa('Moose::Meta::TypeConstraint') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type and builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")) 4 11732 11736
Condition100%6/6
$type and builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
!ll&&!rl&&r
3111732
$type and builtin::blessed($type)
!ll&&!rl&&r
1211733
MC/DC100%3/3
$type and builtin::blessed($type) and $type->isa("Moose::Meta::TypeConstraint")
$type builtin::blessed($type) $type->isa("Moose::Meta::TypeConstraint")
Truth table100%4/4
A and B and C
A= $typeB= builtin::blessed($type)C= $type->isa("Moose::Meta::TypeConstraint")
ABCresult
0XX0
10X0
1100
1111
48 4 throw_exception( InvalidTypeConstraint => registry_object => $self,
49 type => $type
50 );
51 }
52  
53 11732 $self->type_constraints->{$type->name} = $type;
54 }
55  
56 0 ▶sub find_type_constraint {
Subroutine find_type_constraint: not called CC=3 SCAR=24.8
Pod documented
57 0 my ($self, $type_name) = @_;
58 0 ▶ return $self->get_type_constraint($type_name)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_type_constraint($type_name) 0 0 0
59 if $self->has_type_constraint($type_name);
60 0 ▶ return $self->get_parent_registry->find_type_constraint($type_name)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent_registry 0 0 0
61 if $self->has_parent_registry;
62 0 return;
63 }
64  
65 398 1;
66  
67 # ABSTRACT: registry for type constraints
68  
69 __END__
« blib/lib/oose.pm ↑ Summary blib/lib/Moose/Util/MetaRole.pm »