Moose/Meta/TypeConstraint/TypeArray.pm

filter: Statementstmt 80.6% 50 / 62 Branchbran 37.5% 3 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 12 / 16 Podpod 100% 3 / 3 totaltotal 72.3% 68 / 94 CC 9 SCAR 12.5
CC
9
Cov
73%
validate
12.0
get_message
6.0
__ANON__
3.3
CRAP 3.5
↑ Summary MooseX/TypeArray.pm »
1  
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Moose::Meta::TypeConstraint::TypeArray;
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $Moose::Meta::TypeConstraint::TypeArray::VERSION = '0.1.0';
8 }
9  
10 # ABSTRACT: Moose 'TypeArray' Base type constraint type.
11  
12 2 ▶use metaclass;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # use Moose::Meta::TypeCoercion::TypeArray;
15 2 ▶use Moose::Meta::TypeConstraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use parent 'Moose::Meta::TypeConstraint';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 __PACKAGE__->meta->add_attribute(
20 'combining' => (
21 accessor => 'combined_constraints',
22 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 )
24 2 );
25  
26 __PACKAGE__->meta->add_attribute(
27 'internal_name' => (
28 accessor => 'internal_name',
29 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 )
31 2 );
32  
33 2 __PACKAGE__->meta->add_attribute( '_default_message' => ( accessor => '_default_message', ) );
34  
35 1 ▶my $_default_message_generator = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 1 my ( $name, $constraints_ ) = @_;
37 1 my (@constraints) = @{$constraints_};
38  
39 1 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
40 1 my $value = shift;
41 1 require MooseX::TypeArray::Error;
42 1 my %errors = ();
43 1 for my $type (@constraints) {
44 2 ▶ if ( my $error = $type->validate($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $type->validate($value)) 2 0 2
45 2 $errors{ $type->name } = $error;
46 }
47 }
48 1 return MooseX::TypeArray::Error->new(
49 name => $name,
50 value => $value,
51 errors => \%errors,
52 );
53 1 };
54 2 };
55  
56 0 ▶sub get_message {
Subroutine get_message: not called CC=2 SCAR=17.9
Pod documented
57 0 my ( $self, $value ) = @_;
58 0 ▶ my $msg = $self->message || $self->_default_message;
Condition0%0/3
$self->message || $self->_default_message
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->message || $self->_default_message
$self->message $self->_default_message
Truth table0%0/3
A || B
A= $self->messageB= $self->_default_message
ABresult
1X1
011
000
59 0 local $_ = $value;
60 0 return $msg->($value);
61 }
62  
63 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
64 1 my ( $class, %options ) = @_;
65  
66 1 my $name = 'TypeArray(' . ( join q{,}, sort { $a cmp $b } map { $_->name } @{ $options{combining} } ) . ')';
67  
68 1 my $self = $class->SUPER::new(
69 name => $name,
70 internal_name => $name,
71  
72 %options,
73 );
74 1 ▶ $self->_default_message( $_default_message_generator->( $self->name, $self->combined_constraints ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_message 1 0 1
75 unless $self->has_message;
76  
77 1 return $self;
78 }
79  
80 1 ▶sub _actually_compile_type_constraint {
Subroutine _actually_compile_type_constraint: called CC=1 SCAR=0.1
81 1 my $self = shift;
82 1 my @constraints = @{ $self->combined_constraints };
83 1 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
84 1 my $value = shift;
85 1 foreach my $type (@constraints) {
86 1 ▶ return if not $type->check($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $type->check($value) 1 0 1
87 }
88 0 return 1;
89 1 };
90 }
91  
92 0 ▶sub validate {
Subroutine validate: not called CC=3 SCAR=24.8
Pod documented
93 0 my ( $self, $value ) = @_;
94 0 foreach my $type ( @{ $self->combined_constraints } ) {
95 0 ▶ return $self->get_message($value) if defined $type->validate($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $type->validate($value) 0 0 0
96 }
97 0 return;
98 }
99  
100 2 1;
101  
102 __END__
↑ Summary MooseX/TypeArray.pm »