Valiant/Error.pm

filter: Statementstmt 94.5% 175 / 185 Branchbran 75.5% 65 / 86 Conditioncond 72.5% 29 / 40 MC/DCmcdc 40.9% 9 / 22 Subroutinesub 88.8% 16 / 18 Podpod 33.3% 4 / 12 totaltotal 82.0% 298 / 363 CC 61 SCAR 24.3
CC
61
Cov
86%
generate_message
18.2
message
15.8
full_message
11.2
CRAP 11.3
« DBIx/Class/Valiant/ResultSet.pm ↑ Summary Valiant/HTML/Tag/Label.pm »
1 package Valiant::Error;
2  
3 47 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use Text::Autoformat 'autoformat';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 47 ▶use FreezeThaw;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 47 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # These groups are often present in the options hash and need to be removed
10 # before passing options onto other classes in some cases
11  
12 47 my @CALLBACKS_OPTIONS = (qw(if unless on allow_undef allow_blank strict));
13 47 my @MESSAGE_OPTIONS = (qw(message));
14  
15 # object is the underlying object that has an error. This object
16 # must do the 'validatable' role.
17  
18 47 has 'object' => (
19 is => 'ro',
20 required => 1,
21 weak_ref => 1, # not sure about this...
22 );
23  
24 # The type of the error, a string
25 47 has ['type', 'raw_type'] => (
26 is => 'ro',
27 required => 1,
28 );
29  
30 # The attribute that has the error. If undef that means its
31 # a model error (an error on the model itself in general).
32 47 has attribute => (is=>'ro', required=>0, predicate=>'has_attribute');
33  
34 # The value which caused the error.
35 47 has bad_value => (is=>'ro', required=>1);
36  
37 # A hashref of extra meta info (it is allowed to be an empty hash)
38 47 has options => (is=>'ro', required=>1);
39  
40 # holds a local reference to the i18n object
41 47 has i18n => (is=>'ro', required=>1);
42  
43 # Easier to override for subclassers. Do we want to check the options attribute
44 # to make it easier to set without subclassing? Something to think about.
45 4 ▶sub i18n_class { 'Valiant::I18N' }
Subroutine i18n_class: called CC=1 SCAR=0.0
Pod undocumented
46 408 ▶sub default_format { '{{attribute}} {{message}}' }
Subroutine default_format: called CC=1 SCAR=0.0
Pod undocumented
47  
48 around BUILDARGS => sub {
49 560 ▶ my ($orig, $class, @args) = @_;
Subroutine __ANON__: called CC=8 SCAR=20.9
50 560 my $options = $class->$orig(@args);
51  
52 # Pull the main attributes out of the options hashref
53 560 my ($object, $attribute, $type, $i18n, $set_options, $bad_value) = delete @{$options}{qw/object attribute type i18n options bad_value/};
54 # Get the i18n from options if passed, otherwise from the model if the model so
55 # defines it, lastly just make one if we need it.
56 560 ▶ $i18n ||= $object->can('i18n') ?
Branch: 1 branch
BranchTrueFalseTotal
$object->can('i18n') ? : 101 4 105
Condition66%2/3
$i18n ||= $object->can("i18n") ? $object->i18n : &Module::Runtime::use_module(scalar $class->i18n_class)
l!l&&r!l&&!r
4551050
MC/DC0%0/2
$i18n ||= $object->can("i18n") ? $object->i18n : &Module::Runtime::use_module(scalar $class->i18n_class)
$i18n $object->can("i18n") ? $object->i18n : &Module::Runtime::use_module(scalar $class->i18n_class)
Truth table66%2/3
A ||= B
A= $i18nB= $object->can("i18n") ? $object->i18n : &Module::Runtime::use_module(scalar $class->i18n_class)
ABresult
1X1
011
000
57 $object->i18n :
58 Module::Runtime::use_module($class->i18n_class);
59  
60 # set a default error type
61 560 ▶ unless(defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 103 457 560
62 103 $type = $i18n->make_tag('invalid');
63 }
64  
65 560 ▶ unless(defined($bad_value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bad_value) 560 0 560
66 560 ▶ if($attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute) { } 541 19 560
67 541 $bad_value = $object->read_attribute_for_validation($attribute);
68 } else {
69 19 $bad_value = $object; # Its a model error
70 }
71 }
72  
73 return +{
74 object => $object,
75 attribute => $attribute,
76 type => $type,
77 i18n => $i18n,
78 raw_type => $type,
79 bad_value => $bad_value,
80 options => +{
81 560 ▶ %{$options||{}},
Branch: 1 branch
BranchTrueFalseTotal
$options or {} 0 560 560
82 560 ▶ %{$set_options||{}}
Branch: 1 branch
BranchTrueFalseTotal
$set_options or {} 104 456 560
83 },
84 }
85 47 };
86  
87 # This takes an already translated error message part and creates a full message
88 # by combining it with the attribute human name (which itself needs to be translated
89 # if translation info exists for it) using a template 'format'. You can have a format
90 # for each attribute or model/attribute combination or use a default format.
91  
92 sub full_message {
93 421 ▶ my $self = shift;
Subroutine full_message: called CC=11 SCAR=24.2
Pod undocumented
94  
95 # We need to do this dance since full_message needs to be called with two
96 # different signatures. In some places we even call it as a class method
97 # (that's why we do the i18n dance below as well)
98 421 my ($attribute, $message, $object, $i18n) = @_;
99 421 ▶ $attribute ||= $self->attribute if $self->has_attribute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_attribute 421 0 421
Condition66%2/3
$attribute ||= $self->attribute
l!l&&r!l&&!r
040813
MC/DC50%1/2
$attribute ||= $self->attribute
$attribute $self->attribute
Truth table66%2/3
A ||= B
A= $attributeB= $self->attribute
ABresult
1X1
011
000
100 421 ▶ $message ||= $self->message;
Condition33%1/3
$message ||= $self->message
l!l&&r!l&&!r
04210
MC/DC0%0/2
$message ||= $self->message
$message $self->message
Truth table33%1/3
A ||= B
A= $messageB= $self->message
ABresult
1X1
011
000
101 421 ▶ $object ||= $self->object;
Condition33%1/3
$object ||= $self->object
l!l&&r!l&&!r
04210
MC/DC0%0/2
$object ||= $self->object
$object $self->object
Truth table33%1/3
A ||= B
A= $objectB= $self->object
ABresult
1X1
011
000
102 421 ▶ $i18n ||= Scalar::Util::blessed($self) ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 421 0 421
Condition33%1/3
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
l!l&&r!l&&!r
04210
MC/DC0%0/2
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
$i18n builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
Truth table33%1/3
A ||= B
A= $i18nB= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
ABresult
1X1
011
000
103 $self->i18n :
104 Module::Runtime::use_module($self->i18n_class);
105  
106 421 ▶ return $message unless defined($attribute);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 13 408 421
107  
108 408 my @defaults = ();
109 408 ▶ if($object->can('i18n_scope')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("i18n_scope")) 401 7 408
110 401 $attribute =~s/\.\d+//g;
111 401 $attribute =~s/\[\d+\]//g;
112 401 my $i18n_scope = $object->i18n_scope;
113 401 my @parts = split '\.', $attribute; # For nested attributes
114 401 my $attribute_name = pop @parts;
115 401 ▶ my $namespace = join '/', @parts if @parts;
Branch: 1 branch
BranchTrueFalseTotal
if @parts 87 314 401
116 401 my $attributes_scope = "${i18n_scope}.errors.models";
117 401 ▶ if($namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace) { } 87 314 401
118 @defaults = map {
119 155 my $class = $_;
120 155 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.attributes.${attribute_name}.format/@{[ $self->type ]}",
121 155 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.attributes.${attribute_name}.format",
122 155 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.format";
123 87 } grep { $_->model_name->can('i18n_key') } $object->i18n_lookup;
124 } else {
125 @defaults = map {
126 451 my $class = $_;
127 451 "${attributes_scope}.${\$class->model_name->i18n_key}.attributes.${attribute_name}.format/@{[ $self->type ]}",
128 451 "${attributes_scope}.${\$class->model_name->i18n_key}.attributes.${attribute_name}.format",
129 451 "${attributes_scope}.${\$class->model_name->i18n_key}.format";
130 314 } grep { $_->model_name->can('i18n_key') } $object->i18n_lookup;
131 }
132 }
133  
134 408 @defaults = map { $i18n->make_tag($_) } @defaults;
135  
136 408 push @defaults, $i18n->make_tag("errors.format.attributes.${attribute}"); # This isn't in Rails but I find it useful
137 408 push @defaults, $i18n->make_tag("errors.format");
138  
139 # This last one
140 408 push @defaults, $self->default_format;
141  
142 # We do this dance to cope with nested attributes like 'user.name'.
143 408 my $attr_name = do {
144 408 my $human_attr = $attribute;
145 408 $human_attr =~s/\./ /g;
146 408 $human_attr =~s/\[\d+\]//g;
147 408 $human_attr =~s/_id$//; # remove trailing _id
148 408 $human_attr =~s/_/ /g;
149 408 $human_attr = autoformat $human_attr, {case=>'title'};
150 408 $human_attr =~s/[\n]//g; # Is this a bug in Text::Autoformat???
151 408 $human_attr;
152 };
153  
154 408 $attr_name = $object->human_attribute_name($attribute, +{default=>$attr_name});
155  
156 408 return my $translated = $i18n->translate(
157 shift @defaults,
158 default => \@defaults,
159 attribute => $attr_name,
160 message => $message
161 );
162 }
163  
164 # Generates a message part which is a text message of the error
165 # without the attribute or other bits. In rails this is a class
166 # method; I preserved the given API for now but for the most
167 # part you should just call ->message which does the right
168 # thing for this error (or ->full_message).
169  
170 sub generate_message {
171 371 ▶ my ($self, $attribute, $type, $object, $options, $i18n) = @_;
Subroutine generate_message: called CC=17 SCAR=29.0
Pod undocumented
172 371 ▶ $i18n ||= Scalar::Util::blessed($self) ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 371 0 371
Condition33%1/3
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
l!l&&r!l&&!r
03710
MC/DC0%0/2
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
$i18n builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
Truth table33%1/3
A ||= B
A= $i18nB= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
ABresult
1X1
011
000
173 $self->i18n :
174 Module::Runtime::use_module($self->i18n_class);
175  
176 371 ▶ $options ||= +{};
Condition50%1/2
$options ||= {}
l!l
3710
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
177 371 ▶ $type = delete $options->{message} if $i18n->is_i18n_tag($options->{message}||'');
Branch: 1 branch
BranchTrueFalseTotal
if $i18n->is_i18n_tag($options->{"message"} || "") 14 357 371
Condition100%2/2
$options->{'message'} || ''
l!l
14357
MC/DC100%1/1
$options->{'message'} || ''
$options->{'message'}
Truth table100%2/2
A
A= $options->{'message'}
Aresult
11
00
178  
179 371 my $local_attribute;
180 371 ▶ if(defined $attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attribute) 370 1 371
181 370 ▶ $local_attribute = $attribute if defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
if defined $attribute 370 0 370
182 370 $local_attribute =~s/\[\d+\]//g;
183 }
184  
185 # There's only a value associated with this error if there is an attribute
186 # as well. Otherwise its just an error on the model as a whole
187 371 ▶ my $value = defined($local_attribute) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $local_attribute ? : 370 1 371
188 $object->read_attribute_for_validation($local_attribute) :
189 undef;
190  
191 my %options = (
192 model => $object->model_name->human,
193 attribute => defined($local_attribute) ? $object->human_attribute_name($local_attribute, $options) : undef,
194 value => $value,
195 object => $object,
196 371 ▶ %{$options||+{}},
Branch: 2 branches
BranchTrueFalseTotal
defined $local_attribute ? : 370 1 371
$options or {} 0 371 371
197 );
198  
199 371 my @defaults = ();
200 371 ▶ if($object->can('i18n_scope')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("i18n_scope")) 364 7 371
201 364 my $i18n_scope = $object->i18n_scope;
202 @defaults = map {
203 596 my $class = $_;
204 596 ▶ (defined($local_attribute) ? "${i18n_scope}.errors.models.${\$class->model_name->i18n_key}.attributes.${local_attribute}.${$type}" : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $local_attribute ? : 593 3 596
205 596 "${i18n_scope}.errors.models.${\$class->model_name->i18n_key}.${$type}";
206 } grep {
207 364 ▶ $_->model_name->can('i18n_key')
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("i18n_lookup") 363 1 364
208 } $object->i18n_lookup if $object->can('i18n_lookup');
209 364 push @defaults, "${i18n_scope}.errors.messages.${$type}";
210 }
211  
212 371 ▶ push @defaults, "errors.attributes.${local_attribute}.${$type}" if defined($local_attribute);
Branch: 1 branch
BranchTrueFalseTotal
if defined $local_attribute 370 1 371
213 371 push @defaults, "errors.messages.${$type}";
214  
215 371 @defaults = map { $i18n->make_tag($_) } @defaults;
216  
217 371 my $key = shift(@defaults);
218 371 ▶ if($options->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"message"}) 0 371 371
219 0 my $message = delete $options->{message};
220 0 ▶ @defaults = ref($message) ? @$message : ($message);
Branch: 1 branch
BranchTrueFalseTotal
ref $message ? : 0 0 0
221 }
222 371 $options{default} = \@defaults;
223 371 return my $translated = $i18n->translate($key, %options);
224 }
225  
226 sub message {
227 593 ▶ my $self = shift;
Subroutine message: called CC=15 SCAR=27.6
Pod undocumented
228 593 ▶ my $type = exists($self->options->{message}) ? $self->options->{message} : $self->raw_type;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->options->{'message'} ? : 31 562 593
229
230 593 ▶ if($self->i18n->is_i18n_tag($type)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->i18n->is_i18n_tag($type)) { } 371 222 593
elsif ((ref $type || '') eq 'CODE') { } 1 221 222
elsif ((ref $type || '') eq 'SCALAR') { } 9 212 221
231 371 my %options = %{$self->options};
232 371 delete @options{@CALLBACKS_OPTIONS};
233 371 return $self->generate_message($self->attribute, $type, $self->object, \%options);
234 ▶ } elsif((ref($type)||'') eq 'CODE') {
Condition100%2/2
ref $type || ''
l!l
10212
MC/DC100%1/1
ref $type || ''
ref $type
Truth table100%2/2
A
A= ref $type
Aresult
11
00
235 1 my $attribute = $self->attribute;
236 1 ▶ my $value = defined($attribute) ? $self->object->read_attribute_for_validation($attribute) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $attribute ? : 1 0 1
237 my %options = (
238 model => $self->object->model_name->human,
239 attribute => defined($attribute) ? $self->object->human_attribute_name($attribute, $self->options) : undef,
240 value => $value,
241 object => $self->object,
242 1 ▶ %{$self->options||+{}},
Branch: 2 branches
BranchTrueFalseTotal
defined $attribute ? : 1 0 1
$self->options or {} 0 1 1
243 );
244 1 delete @options{@CALLBACKS_OPTIONS, @MESSAGE_OPTIONS};
245 1 my $return = $type->($self->object, $attribute, $value, \%options);
246 # Allow a coderef to either return a straight up string or a translation tag
247 1 ▶ return $self->i18n->is_i18n_tag($return) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->i18n->is_i18n_tag($return) ? : 0 1 1
248 $self->generate_message($self->attribute, $return, $self->object, \%options) :
249 $return;
250 ▶ } elsif((ref($type)||'') eq 'SCALAR') {
Condition100%2/2
ref $type || ''
l!l
9212
MC/DC100%1/1
ref $type || ''
ref $type
Truth table100%2/2
A
A= ref $type
Aresult
11
00
251 9 my $attribute = $self->attribute;
252 9 ▶ my $value = defined($attribute) ? $self->object->read_attribute_for_validation($attribute) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $attribute ? : 9 0 9
253 my %options = (
254 model => $self->object->model_name->human,
255 attribute => defined($attribute) ? $self->object->human_attribute_name($attribute, $self->options) : undef,
256 value => $value,
257 object => $self->object,
258 9 ▶ %{$self->options||+{}},
Branch: 2 branches
BranchTrueFalseTotal
defined $attribute ? : 9 0 9
$self->options or {} 0 9 9
259 );
260 9 delete @options{@CALLBACKS_OPTIONS, @MESSAGE_OPTIONS};
261  
262 9 my $translated = $$type;
263 9 ▶ $translated =~ s/\{\{([^}]+)\}\}/ defined($options{$1}) ? $options{$1} : '' /gex;
Branch: 1 branch
BranchTrueFalseTotal
defined $options{$1} ? : 12 0 12
264 9 return $translated;
265 } else {
266 # Its just a plain string
267 212 return $type;
268 }
269 }
270  
271 sub detail {
272 0 ▶ my $self = shift;
Subroutine detail: not called CC=1 SCAR=6.9
Pod undocumented
273 0 my %options = %{$self->options};
274 0 delete @options{@CALLBACKS_OPTIONS, @MESSAGE_OPTIONS};
275 return +{
276 0 error => $self->raw_type,
277 %options,
278 };
279 }
280  
281 # This match returns true if at least some bits match
282 sub match {
283 2652 ▶ my ($self, $attribute, $type, $options) = @_;
Subroutine match: called CC=11 SCAR=24.0
Pod documented
284 2652 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (($attribute || "") ne ($self->attribute || "") or $type and $self->type ne $type) 2384 268 2652
Condition100%10/10
($attribute || "") ne ($self->attribute || "") or $type and $self->type ne $type
l!l&&r!l&&!r
23822268
$attribute || ''
l!l
26502
$self->attribute || ''
l!l
2371281
$type and $self->type ne $type
!ll&&!rl&&r
26352
MC/DC66%2/3
($attribute || "") ne ($self->attribute || "") or $type and $self->type ne $type
$attribute $type $self->type ne $type
MC/DC100%1/1
$self->attribute || ''
$self->attribute
Truth table75%3/4
A or B and C
A= $attributeB= $typeC= $self->type ne $type
ABCresult
1XX1
0111
00X0
0100
Truth table100%2/2
A
A= $self->attribute
Aresult
11
00
285 ($attribute||'') ne ($self->attribute||'')
286 ||
287 ($type && ($self->type ne $type))
288 ) {
289 2384 return 0;
290 }
291  
292 # only the passed options need to match. So if there's options
293 # in the error object that are not in the passed options its
294 # still ok to match.
295 268 ▶ foreach my $key (%{$options||+{}}) {
Branch: 1 branch
BranchTrueFalseTotal
$options or {} 267 1 268
296 4 ▶ if( ($self->options->{$key}||'') ne ($options->{$key}||'')) {
Branch: 1 branch
BranchTrueFalseTotal
if (($self->options->{$key} || "") ne ($options->{$key} || "")) 0 4 4
Condition100%4/4
$self->options->{$key} || ''
l!l
22
$options->{$key} || ''
l!l
22
MC/DC100%1/1
$self->options->{$key} || ''
$self->options->{$key}
MC/DC100%1/1
$options->{$key} || ''
$options->{$key}
Truth table100%2/2
A
A= $self->options->{$key}
Aresult
11
00
Truth table100%2/2
A
A= $options->{$key}
Aresult
11
00
297 0 return 0;
298 }
299 }
300 268 return 1;
301 }
302  
303 sub clone {
304 2 ▶ my $self = shift;
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
305 2 my $class = ref $self;
306 2 return $class->new(
307 object => $self->object,
308 attribute => $self->attribute,
309 type => $self->type,
310 i18n => $self->i18n,
311 options => $self->options,
312 );
313 }
314  
315 sub strict_match {
316 2 ▶ my ($self, $attribute, $type, $options) = @_;
Subroutine strict_match: called CC=3 SCAR=11.0
Pod documented
317 2 ▶ return 0 unless $self->match($attribute, $type);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->match($attribute, $type) 0 2 2
318  
319 # This is different from match because ALL the keys/values in options need to match
320 # exactly. Its possible my approach here is suspect around object comparisons.
321 2 my %options = %{$self->options};
322 2 delete @options{@CALLBACKS_OPTIONS, @MESSAGE_OPTIONS};
323  
324 2 ▶ return FreezeThaw::cmpStr(\%options, $options) == 0 ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
FreezeThaw::cmpStr(\%options, $options) == 0 ? : 1 1 2
325 }
326  
327 # Are two errors the same?
328 sub equals {
329 7 ▶ my ($self, $target) = @_;
Subroutine equals: called CC=2 SCAR=7.0
Pod documented
330  
331 7 ▶ return 0 unless ref($self) eq ref($target);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq ref $target 0 7 7
332  
333 7 my $a = FreezeThaw::freeze $self->attributes_for_hash;
334 7 my $b = FreezeThaw::freeze $target->attributes_for_hash;
335  
336 7 return $a eq $b;
337 }
338  
339 sub hash {
340 0 ▶ my $self = shift;
Subroutine hash: not called CC=1 SCAR=6.9
Pod undocumented
341 0 return +{ $self->attributes_for_hash };
342 }
343  
344 sub attributes_for_hash {
345 14 ▶ my $self = shift;
Subroutine attributes_for_hash: called CC=1 SCAR=0.0
Pod undocumented
346 14 my %options = %{$self->options};
347 14 delete @options{@CALLBACKS_OPTIONS};
348  
349 return (
350 object => $self->object,
351 attribute => $self->attribute,
352 raw_type => $self->raw_type,
353 14 map { $_ => $options{$_} } sort keys %options, # This needs sorting to support checking equality
354 );
355 }
356  
357 =head1 NAME
358  
359 Valiant::Error - A single error encountered during validation.
360  
361 =head1 SYNOPSIS
362  
363 This won't be used standalone. Its always a collection of Error objects
364 inside the Valiant::Errors module.
365  
366 =head1 DESCRIPTION
367  
368 A Single Error.
369  
370 This is generally an internal class and you are unlikely to use it directly. For
371 the most part its used by L<Valiant::Errors>.
372  
373 =head1 ATTRIBUTES
374  
375 This class defines the following attributes
376  
377 =head2 type
378  
379 Either a translation tag or text string of the error
380  
381 =head2 attribute
382  
383 The attribute which is associated with the error or undef if the error
384 is for the model
385  
386 =head1 METHODS
387  
388 This class exposes the following methods for public users.
389  
390 =head2 match ($attribute, $type, $options)
391  
392 Returns true of the error matches (has the same parameters) as the arguments
393 passed. This differs from L</strict_match> in that C<$options> don't need to
394 be completely identical; it must ony be the case that the C<$options> passed
395 in the arguments intersects with that actual options of the error (that is
396 the error has to have everything in C<$options> BUT it can have more things.
397  
398 =head2 strict_match ($attribute, $type, $options)
399  
400 Same as L</match> except <$options> must exactly match and not just intersect.
401  
402 =head2 equals ($error)
403  
404 Returna a boolean based on if C<$error> is functionally equal. By this it is meant
405 that it has the same attribute values (not that it is the same error instance).
406  
407 This includes C<options> matching.
408  
409 =head2 clone
410  
411 Create a new copy of the error.
412  
413 =head1 SEE ALSO
414
415 L<Valiant>, L<Valiant::Errors>.
416  
417 =head1 AUTHOR
418
419 See L<Valiant>
420
421 =head1 COPYRIGHT & LICENSE
422
423 See L<Valiant>
424  
425 =cut
426  
427 47 1;
« DBIx/Class/Valiant/ResultSet.pm ↑ Summary Valiant/HTML/Tag/Label.pm »