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