line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
913
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package MooseX::TypeArray::Error; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
16
|
$MooseX::TypeArray::Error::VERSION = '0.1.0'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Information container for validation failures from MooseX::TypeArrays' constraints |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
448
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Try::Tiny; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#use Class::Load; |
15
|
|
|
|
|
|
|
use overload '""' => \&get_message; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#with 'StackTrace::Auto'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'name' => ( |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'value' => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
required => 1, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'errors' => ( |
34
|
|
|
|
|
|
|
isa => 'HashRef', |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'message' => ( |
41
|
|
|
|
|
|
|
isa => 'CodeRef', |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
predicate => 'has_message', |
44
|
|
|
|
|
|
|
traits => ['Code'], |
45
|
|
|
|
|
|
|
handles => { '_message' => 'execute', }, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has '_stack_trace' => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => 'CodeRef', |
52
|
|
|
|
|
|
|
builder => '_build_stack_trace', |
53
|
|
|
|
|
|
|
init_arg => undef, |
54
|
|
|
|
|
|
|
required => 1, |
55
|
|
|
|
|
|
|
traits => ['Code'], |
56
|
|
|
|
|
|
|
handles => { 'stack_trace' => 'execute' }, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _build_stack_trace { |
60
|
|
|
|
|
|
|
require Devel::StackTrace; |
61
|
|
|
|
|
|
|
my $found_mark = 0; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# my $uplevel = 6; |
64
|
|
|
|
|
|
|
my $trace = Devel::StackTrace->new( |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# no_refs => 1, |
67
|
|
|
|
|
|
|
indent => 1, |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# frame_filter => sub { |
70
|
|
|
|
|
|
|
# my ($raw) = @_; |
71
|
|
|
|
|
|
|
# if ($found_mark) { |
72
|
|
|
|
|
|
|
# return 1 unless $uplevel; |
73
|
|
|
|
|
|
|
# return !$uplevel--; |
74
|
|
|
|
|
|
|
# } |
75
|
|
|
|
|
|
|
# else { |
76
|
|
|
|
|
|
|
# $found_mark = scalar $raw->{caller}->[3] =~ /new$/; |
77
|
|
|
|
|
|
|
# return 0; |
78
|
|
|
|
|
|
|
# } |
79
|
|
|
|
|
|
|
# } |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# this is to hide the guts of the stacktrace if you pass it to a dumper. Its far too bloaty. |
83
|
|
|
|
|
|
|
return sub { $trace }; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_message { |
88
|
|
|
|
|
|
|
my ($self) = @_; |
89
|
|
|
|
|
|
|
if ( $self->has_message ) { |
90
|
|
|
|
|
|
|
local $_ = $self->value; |
91
|
|
|
|
|
|
|
return $self->_message( $self, $_ ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
my $value = $self->value; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Stolen liberally from Moose::Meta::TypeConstraint; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# have to load it late like this, since it uses Moose itself |
98
|
|
|
|
|
|
|
my $can_partialdump = try { |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# versions prior to 0.14 had a potential infinite loop bug |
101
|
|
|
|
|
|
|
Class::MOP::load_class( 'Devel::PartialDump', { -version => 0.14 } ); |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
if ($can_partialdump) { |
105
|
|
|
|
|
|
|
$value = Devel::PartialDump->new->dump($value); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
|
|
|
|
|
|
$value = ( defined $value ? overload::StrVal($value) : 'undef' ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
my @lines = ( 'Validation failed for \'' . $self->name . '\' with value ' . $value . ' :' ); |
111
|
|
|
|
|
|
|
my $index = 0; |
112
|
|
|
|
|
|
|
push @lines, q{ -- }; |
113
|
|
|
|
|
|
|
for my $suberror ( sort keys %{ $self->errors } ) { |
114
|
|
|
|
|
|
|
$index++; |
115
|
|
|
|
|
|
|
my $errorstr = q{} . $self->errors->{$suberror}; |
116
|
|
|
|
|
|
|
push @lines, sprintf q{ %s. %s: }, $index, $suberror; |
117
|
|
|
|
|
|
|
## no critic ( ProhibitComplexMappings ) |
118
|
|
|
|
|
|
|
push @lines, map { ( my $x = $_ ) =~ s/\A/ /msx; $x } split /\n/msx, $errorstr; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
push @lines, q{ -- }; |
121
|
|
|
|
|
|
|
push @lines, $self->stack_trace->as_string; |
122
|
|
|
|
|
|
|
return join qq{\n}, @lines; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
no Moose; |
126
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
=pod |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 NAME |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
MooseX::TypeArray::Error - Information container for validation failures from MooseX::TypeArrays' constraints |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 VERSION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
version 0.1.0 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 METHODS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 get_message |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 name |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 value |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 errors |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 message |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 PRIVATE ATTRIBUTES |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 _stack_trace |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Kent Fredric <kentnl@cpan.org>. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
169
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|