line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
1
|
|
|
1
|
|
1204
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Moose::Meta::TypeConstraint::TypeArray; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
35
|
$Moose::Meta::TypeConstraint::TypeArray::AUTHORITY = 'cpan:KENTNL'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
$Moose::Meta::TypeConstraint::TypeArray::VERSION = '0.2.0'; # TRIAL |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# ABSTRACT: Moose 'TypeArray' Base type constraint type. |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
421
|
use metaclass; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use Moose::Meta::TypeCoercion::TypeArray; |
18
|
|
|
|
|
|
|
use Moose::Meta::TypeConstraint; |
19
|
|
|
|
|
|
|
use Try::Tiny; |
20
|
|
|
|
|
|
|
use parent 'Moose::Meta::TypeConstraint'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
23
|
|
|
|
|
|
|
'combining' => ( |
24
|
|
|
|
|
|
|
accessor => 'combined_constraints', |
25
|
|
|
|
|
|
|
default => sub { [] }, |
26
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
27
|
|
|
|
|
|
|
) |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
31
|
|
|
|
|
|
|
'internal_name' => ( |
32
|
|
|
|
|
|
|
accessor => 'internal_name', |
33
|
|
|
|
|
|
|
default => sub { [] }, |
34
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
35
|
|
|
|
|
|
|
) |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute( |
39
|
|
|
|
|
|
|
'_default_message' => ( |
40
|
|
|
|
|
|
|
accessor => '_default_message', |
41
|
|
|
|
|
|
|
Class::MOP::_definition_context(), |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $_default_message_generator = sub { |
46
|
|
|
|
|
|
|
my ( $name, $constraints_ ) = @_; |
47
|
|
|
|
|
|
|
my (@constraints) = @{$constraints_}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return sub { |
50
|
|
|
|
|
|
|
my $value = shift; |
51
|
|
|
|
|
|
|
require MooseX::TypeArray::Error; |
52
|
|
|
|
|
|
|
my %errors = (); |
53
|
|
|
|
|
|
|
for my $type (@constraints) { |
54
|
|
|
|
|
|
|
if ( my $error = $type->validate($value) ) { |
55
|
|
|
|
|
|
|
$errors{ $type->name } = $error; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
return MooseX::TypeArray::Error->new( |
59
|
|
|
|
|
|
|
name => $name, |
60
|
|
|
|
|
|
|
value => $value, |
61
|
|
|
|
|
|
|
errors => \%errors, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_message { |
67
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
68
|
|
|
|
|
|
|
my $msg = $self->message || $self->_default_message; |
69
|
|
|
|
|
|
|
local $_ = $value; |
70
|
|
|
|
|
|
|
return $msg->($value); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new { |
74
|
|
|
|
|
|
|
my ( $class, %options ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $name = 'TypeArray(' . ( join q{,}, sort { $a cmp $b } map { $_->name } @{ $options{combining} } ) . ')'; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $self = $class->SUPER::new( |
79
|
|
|
|
|
|
|
name => $name, |
80
|
|
|
|
|
|
|
internal_name => $name, |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
%options, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
$self->_default_message( $_default_message_generator->( $self->name, $self->combined_constraints ) ) |
85
|
|
|
|
|
|
|
unless $self->has_message; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _actually_compile_type_constraint { |
91
|
|
|
|
|
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
my @constraints = @{ $self->combined_constraints }; |
93
|
|
|
|
|
|
|
return sub { |
94
|
|
|
|
|
|
|
my $value = shift; |
95
|
|
|
|
|
|
|
foreach my $type (@constraints) { |
96
|
|
|
|
|
|
|
return if not $type->check($value); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return 1; |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub validate { |
103
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
104
|
|
|
|
|
|
|
foreach my $type ( @{ $self->combined_constraints } ) { |
105
|
|
|
|
|
|
|
return $self->get_message($value) if defined $type->validate($value); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=pod |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=encoding UTF-8 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Moose::Meta::TypeConstraint::TypeArray - Moose 'TypeArray' Base type constraint type. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 VERSION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
version 0.2.0 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Kent Fredric <kentnl@cpan.org>. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |