line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2445
|
use 5.006; # warnings |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
46
|
|
2
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
19
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package MooseX::Attribute::ValidateWithException::AttributeRole; |
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
227
|
$MooseX::Attribute::ValidateWithException::AttributeRole::AUTHORITY = 'cpan:KENTNL'; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
$MooseX::Attribute::ValidateWithException::AttributeRole::VERSION = '0.3.1'; |
11
|
|
|
|
|
|
|
} |
12
|
1
|
|
|
1
|
|
493
|
use Moose::Role qw( override ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub __generate_check { |
15
|
|
|
|
|
|
|
my ( $self, %params ) = @_; |
16
|
|
|
|
|
|
|
if ( $self->type_constraint->can_be_inlined ) { |
17
|
|
|
|
|
|
|
## no critic (ProtectPrivateSubs) |
18
|
|
|
|
|
|
|
return sprintf '( %s )', $self->type_constraint->_inline_check( $params{value} ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
|
|
|
|
|
|
return sprintf '( %s->( %s ) )', $params{tc}, $params{value}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
override '_inline_check_constraint' => sub { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my ( $value, $tc, $message, $is_lazy ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $attribute_name = quotemeta( $self->name ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return unless $self->has_type_constraint; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $tc_obj = $self->type_constraint; |
35
|
|
|
|
|
|
|
my $tc_name = quotemeta( $tc_obj->name ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## no critic ( ProhibitImplicitNewlines RequireInterpolationOfMetachars ) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $check_code = $self->__generate_check( value => $value, tc => $tc, ); |
40
|
|
|
|
|
|
|
my $message_variable = '$message'; |
41
|
|
|
|
|
|
|
my $get_message_code = ( sprintf 'do { local $_ = %s; %s->( %s ) }', $value, $message, $value, ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return <<"CHECKCODE"; |
44
|
|
|
|
|
|
|
if( ! $check_code ) { |
45
|
|
|
|
|
|
|
my $message_variable = $get_message_code; |
46
|
|
|
|
|
|
|
if ( ref $message_variable ) { |
47
|
|
|
|
|
|
|
die $message_variable; |
48
|
|
|
|
|
|
|
} else { |
49
|
|
|
|
|
|
|
require MooseX::Attribute::ValidateWithException::Exception; |
50
|
|
|
|
|
|
|
die MooseX::Attribute::ValidateWithException::Exception->new( |
51
|
|
|
|
|
|
|
attribute_name => '$attribute_name', |
52
|
|
|
|
|
|
|
data => $value, |
53
|
|
|
|
|
|
|
constraint_message => $message_variable, |
54
|
|
|
|
|
|
|
constraint_name => '$tc_name', |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
CHECKCODE |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
override 'verify_against_type_constraint' => sub { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
my $val = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return 1 if !$self->has_type_constraint; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $type_constraint = $self->type_constraint; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if ( not $type_constraint->check($val) ) { |
70
|
|
|
|
|
|
|
my $message = $type_constraint->get_message($val); |
71
|
|
|
|
|
|
|
if ( ref $message ) { |
72
|
|
|
|
|
|
|
die $message; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
else { |
75
|
|
|
|
|
|
|
require MooseX::Attribute::ValidateWithException::Exception; |
76
|
|
|
|
|
|
|
die MooseX::Attribute::ValidateWithException::Exception->new( |
77
|
|
|
|
|
|
|
attribute_name => $self->name, |
78
|
|
|
|
|
|
|
data => $val, |
79
|
|
|
|
|
|
|
constraint_message => $message, |
80
|
|
|
|
|
|
|
constraint => $type_constraint, |
81
|
|
|
|
|
|
|
constraint_name => $type_constraint->name, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
no Moose::Role; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=pod |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=encoding UTF-8 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
MooseX::Attribute::ValidateWithException::AttributeRole |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 0.3.1 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Kent Fredric <kentnl@cpan.org>. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
114
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |