Valiant/Error.pm

filter: Statementstmt 94.5% 173 / 183 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 81.9% 296 / 361 CC 61 SCAR 24.3
CC
61
Cov
86%
generate_message
18.2
message
15.8
full_message
11.2
CRAP 11.3
« Valiant/HTML/Util/TagBuilder.pm ↑ Summary Valiant/HTML/Tag/Label.pm »
1 package Valiant::Error;
2  
3 45 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use Text::Autoformat 'autoformat';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 45 ▶use FreezeThaw;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 45 ▶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 45 my @CALLBACKS_OPTIONS = (qw(if unless on allow_undef allow_blank strict));
13 45 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 45 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 45 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 45 has attribute => (is=>'ro', required=>0, predicate=>'has_attribute');
33  
34 # The value which caused the error.
35 45 has bad_value => (is=>'ro', required=>1);
36  
37 # A hashref of extra meta info (it is allowed to be an empty hash)
38 45 has options => (is=>'ro', required=>1);
39  
40 # holds a local reference to the i18n object
41 45 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 376 ▶sub default_format { '{{attribute}} {{message}}' }
Subroutine default_format: called CC=1 SCAR=0.0
Pod undocumented
47  
48 around BUILDARGS => sub {
49 536 ▶ my ($orig, $class, @args) = @_;
Subroutine __ANON__: called CC=8 SCAR=20.9
50 536 my $options = $class->$orig(@args);
51  
52 # Pull the main attributes out of the options hashref
53 536 my ($object, $attribute, $type, $i18n, $set_options, $bad_value) = delete @{$options}{qw/object attribute type i18n options bad_value/};
54  
55 # Get the i18n from options if passed, otherwise from the model if the model so
56 # defines it, lastly just make one if we need it.
57 536 ▶ $i18n ||= $object->can('i18n') ?
Branch: 1 branch
BranchTrueFalseTotal
$object->can('i18n') ? : 97 4 101
Condition66%2/3
$i18n ||= $object->can("i18n") ? $object->i18n : &Module::Runtime::use_module(scalar $class->i18n_class)
l!l&&r!l&&!r
4351010
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
58 $object->i18n :
59 Module::Runtime::use_module($class->i18n_class);
60  
61 # set a default error type
62 536 ▶ unless(defined($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type) 99 437 536
63 99 $type = $i18n->make_tag('invalid');
64 }
65  
66 536 ▶ unless(defined($bad_value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $bad_value) 536 0 536
67 536 ▶ if($attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute) { } 516 20 536
68 516 $bad_value = $object->read_attribute_for_validation($attribute);
69 } else {
70 20 $bad_value = $object; # Its a model error
71 }
72 }
73  
74 return +{
75 object => $object,
76 attribute => $attribute,
77 type => $type,
78 i18n => $i18n,
79 raw_type => $type,
80 bad_value => $bad_value,
81 options => +{
82 536 ▶ %{$options||{}},
Branch: 1 branch
BranchTrueFalseTotal
$options or {} 0 536 536
83 536 ▶ %{$set_options||{}}
Branch: 1 branch
BranchTrueFalseTotal
$set_options or {} 100 436 536
84 },
85 }
86 45 };
87  
88 # This takes an already translated error message part and creates a full message
89 # by combining it with the attribute human name (which itself needs to be translated
90 # if translation info exists for it) using a template 'format'. You can have a format
91 # for each attribute or model/attribute combination or use a default format.
92  
93 sub full_message {
94 388 ▶ my $self = shift;
Subroutine full_message: called CC=11 SCAR=24.2
Pod undocumented
95  
96 # We need to do this dance since full_message needs to be called with two
97 # different signatures. In some places we even call it as a class method
98 # (that's why we do the i18n dance below as well)
99 388 my ($attribute, $message, $object, $i18n) = @_;
100 388 ▶ $attribute ||= $self->attribute if $self->has_attribute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_attribute 388 0 388
Condition66%2/3
$attribute ||= $self->attribute
l!l&&r!l&&!r
037612
MC/DC50%1/2
$attribute ||= $self->attribute
$attribute $self->attribute
Truth table66%2/3
A ||= B
A= $attributeB= $self->attribute
ABresult
1X1
011
000
101 388 ▶ $message ||= $self->message;
Condition33%1/3
$message ||= $self->message
l!l&&r!l&&!r
03880
MC/DC0%0/2
$message ||= $self->message
$message $self->message
Truth table33%1/3
A ||= B
A= $messageB= $self->message
ABresult
1X1
011
000
102 388 ▶ $object ||= $self->object;
Condition33%1/3
$object ||= $self->object
l!l&&r!l&&!r
03880
MC/DC0%0/2
$object ||= $self->object
$object $self->object
Truth table33%1/3
A ||= B
A= $objectB= $self->object
ABresult
1X1
011
000
103 388 ▶ $i18n ||= Scalar::Util::blessed($self) ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 388 0 388
Condition33%1/3
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
l!l&&r!l&&!r
03880
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
104 $self->i18n :
105 Module::Runtime::use_module($self->i18n_class);
106  
107 388 ▶ return $message unless defined($attribute);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attribute 12 376 388
108  
109 376 my @defaults = ();
110 376 ▶ if($object->can('i18n_scope')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("i18n_scope")) 369 7 376
111 369 $attribute =~s/\.\d+//g;
112 369 my $i18n_scope = $object->i18n_scope;
113 369 my @parts = split '\.', $attribute; # For nested attributes
114 #TODO remove array indexes [\d]
115 369 my $attribute_name = pop @parts;
116 369 ▶ my $namespace = join '/', @parts if @parts;
Branch: 1 branch
BranchTrueFalseTotal
if @parts 75 294 369
117 369 my $attributes_scope = "${i18n_scope}.errors.models";
118 369 ▶ if($namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace) { } 75 294 369
119 @defaults = map {
120 131 my $class = $_;
121 131 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.attributes.${attribute_name}.format/@{[ $self->type ]}",
122 131 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.attributes.${attribute_name}.format",
123 131 "${attributes_scope}.${\$class->model_name->i18n_key}/${namespace}.format";
124 75 } grep { $_->model_name->can('i18n_key') } $object->i18n_lookup;
125 } else {
126 @defaults = map {
127 417 my $class = $_;
128 417 "${attributes_scope}.${\$class->model_name->i18n_key}.attributes.${attribute_name}.format/@{[ $self->type ]}",
129 417 "${attributes_scope}.${\$class->model_name->i18n_key}.attributes.${attribute_name}.format",
130 417 "${attributes_scope}.${\$class->model_name->i18n_key}.format";
131 294 } grep { $_->model_name->can('i18n_key') } $object->i18n_lookup;
132 }
133 }
134  
135 376 @defaults = map { $i18n->make_tag($_) } @defaults;
136  
137 376 push @defaults, $i18n->make_tag("errors.format.attributes.${attribute}"); # This isn't in Rails but I find it useful
138 376 push @defaults, $i18n->make_tag("errors.format");
139  
140 # This last one
141 376 push @defaults, $self->default_format;
142  
143 # We do this dance to cope with nested attributes like 'user.name'.
144 376 my $attr_name = do {
145 376 my $human_attr = $attribute;
146 376 $human_attr =~s/\./ /g;
147 376 $human_attr =~s/_id$//; # remove trailing _id
148 376 $human_attr =~s/_/ /g;
149 376 $human_attr = autoformat $human_attr, {case=>'title'};
150 376 $human_attr =~s/[\n]//g; # Is this a bug in Text::Autoformat???
151 376 $human_attr;
152 };
153
154 376 $attr_name = $object->human_attribute_name($attribute, +{default=>$attr_name});
155  
156 376 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 338 ▶ my ($self, $attribute, $type, $object, $options, $i18n) = @_;
Subroutine generate_message: called CC=17 SCAR=29.0
Pod undocumented
172 338 ▶ $i18n ||= Scalar::Util::blessed($self) ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) ? : 338 0 338
Condition33%1/3
$i18n ||= builtin::blessed($self) ? $self->i18n : &Module::Runtime::use_module(scalar $self->i18n_class)
l!l&&r!l&&!r
03380
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 338 ▶ $options ||= +{};
Condition50%1/2
$options ||= {}
l!l
3380
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
Aresult
11
00
177 338 ▶ $type = delete $options->{message} if $i18n->is_i18n_tag($options->{message}||'');
Branch: 1 branch
BranchTrueFalseTotal
if $i18n->is_i18n_tag($options->{"message"} || "") 14 324 338
Condition100%2/2
$options->{'message'} || ''
l!l
14324
MC/DC100%1/1
$options->{'message'} || ''
$options->{'message'}
Truth table100%2/2
A
A= $options->{'message'}
Aresult
11
00
178  
179 # There's only a value associated with this error if there is an attribute
180 # as well. Otherwise its just an error on the model as a whole
181 338 ▶ my $value = defined($attribute) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $attribute ? : 337 1 338
182 $object->read_attribute_for_validation($attribute) :
183 undef;
184  
185 my %options = (
186 model => $object->model_name->human,
187 attribute => defined($attribute) ? $object->human_attribute_name($attribute, $options) : undef,
188 value => $value,
189 object => $object,
190 338 ▶ %{$options||+{}},
Branch: 2 branches
BranchTrueFalseTotal
defined $attribute ? : 337 1 338
$options or {} 0 338 338
191 );
192  
193 338 my @defaults = ();
194 338 ▶ if($object->can('i18n_scope')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("i18n_scope")) 331 7 338
195 331 my $i18n_scope = $object->i18n_scope;
196 331 my $local_attribute;
197 331 ▶ if(defined $attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attribute) 330 1 331
198 330 ▶ $local_attribute = $attribute if defined $attribute;
Branch: 1 branch
BranchTrueFalseTotal
if defined $attribute 330 0 330
199 330 $local_attribute =~s/\[\d+\]//g;
200 }
201  
202 @defaults = map {
203 538 my $class = $_;
204 538 ▶ (defined($local_attribute) ? "${i18n_scope}.errors.models.${\$class->model_name->i18n_key}.attributes.${local_attribute}.${$type}" : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $local_attribute ? : 535 3 538
205 538 "${i18n_scope}.errors.models.${\$class->model_name->i18n_key}.${$type}";
206 } grep {
207 331 ▶ $_->model_name->can('i18n_key')
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("i18n_lookup") 330 1 331
208 } $object->i18n_lookup if $object->can('i18n_lookup');
209 331 push @defaults, "${i18n_scope}.errors.messages.${$type}";
210 }
211  
212 338 ▶ push @defaults, "errors.attributes.${attribute}.${$type}" if defined($attribute);
Branch: 1 branch
BranchTrueFalseTotal
if defined $attribute 337 1 338
213 338 push @defaults, "errors.messages.${$type}";
214  
215 338 @defaults = map { $i18n->make_tag($_) } @defaults;
216  
217 338 my $key = shift(@defaults);
218 338 ▶ if($options->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"message"}) 0 338 338
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 338 $options{default} = \@defaults;
223 338 return my $translated = $i18n->translate($key, %options);
224 }
225  
226 sub message {
227 556 ▶ my $self = shift;
Subroutine message: called CC=15 SCAR=27.6
Pod undocumented
228 556 ▶ my $type = exists($self->options->{message}) ? $self->options->{message} : $self->raw_type;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->options->{'message'} ? : 31 525 556
229
230 556 ▶ if($self->i18n->is_i18n_tag($type)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->i18n->is_i18n_tag($type)) { } 338 218 556
elsif ((ref $type || '') eq 'CODE') { } 1 217 218
elsif ((ref $type || '') eq 'SCALAR') { } 9 208 217
231 338 my %options = %{$self->options};
232 338 delete @options{@CALLBACKS_OPTIONS};
233 338 return $self->generate_message($self->attribute, $type, $self->object, \%options);
234 ▶ } elsif((ref($type)||'') eq 'CODE') {
Condition100%2/2
ref $type || ''
l!l
10208
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
9208
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 208 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 1630 ▶ my ($self, $attribute, $type, $options) = @_;
Subroutine match: called CC=11 SCAR=24.0
Pod documented
284 1630 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (($attribute || "") ne ($self->attribute || "") or $type and $self->type ne $type) 1453 177 1630
Condition100%10/10
($attribute || "") ne ($self->attribute || "") or $type and $self->type ne $type
l!l&&r!l&&!r
14512177
$attribute || ''
l!l
16282
$self->attribute || ''
l!l
1455175
$type and $self->type ne $type
!ll&&!rl&&r
17252
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 1453 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 177 ▶ foreach my $key (%{$options||+{}}) {
Branch: 1 branch
BranchTrueFalseTotal
$options or {} 176 1 177
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 177 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 45 1;
« Valiant/HTML/Util/TagBuilder.pm ↑ Summary Valiant/HTML/Tag/Label.pm »