| 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
| |||||||||||||||||||||
| 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
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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 2 | 1; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||