| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ABSTRACT: Default Directive for Validation Class Field Definitions | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Validation::Class::Directive::Default; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 109 |  |  | 109 |  | 44348 | use strict; | 
|  | 109 |  |  |  |  | 236 |  | 
|  | 109 |  |  |  |  | 2658 |  | 
| 6 | 109 |  |  | 109 |  | 493 | use warnings; | 
|  | 109 |  |  |  |  | 209 |  | 
|  | 109 |  |  |  |  | 5932 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 109 |  |  | 109 |  | 596 | use base 'Validation::Class::Directive'; | 
|  | 109 |  |  |  |  | 3122 |  | 
|  | 109 |  |  |  |  | 9004 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 109 |  |  | 109 |  | 651 | use Validation::Class::Util; | 
|  | 109 |  |  |  |  | 242 |  | 
|  | 109 |  |  |  |  | 616 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '7.900058'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has 'mixin'        => 1; | 
| 16 |  |  |  |  |  |  | has 'field'        => 1; | 
| 17 |  |  |  |  |  |  | has 'multi'        => 1; | 
| 18 |  |  |  |  |  |  | has 'dependencies' => sub {{ | 
| 19 |  |  |  |  |  |  | normalization  => ['filters', 'readonly'], | 
| 20 |  |  |  |  |  |  | # note: default-values are only handled during normalization now | 
| 21 |  |  |  |  |  |  | # validation   => ['multiples', 'value'] | 
| 22 |  |  |  |  |  |  | }}; | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub normalize { | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 1009 |  |  | 1009 | 0 | 2242 | my ($self, $proto, $field, $param) = @_; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # override parameter value if default exists | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 1009 | 100 | 100 |  |  | 2899 | if (defined $field->{default} && ! defined $param) { | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | my @defaults = isa_arrayref($field->{default}) ? | 
| 33 | 1 |  |  |  |  | 108 | @{$field->{default}} : ($field->{default}) | 
| 34 | 4 | 100 |  |  |  | 13 | ; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 4 |  |  |  |  | 25 | my $context = $proto->stash->{'normalization.context'}; | 
| 37 | 4 |  |  |  |  | 10 | my $name    = $field->name; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 4 |  |  |  |  | 9 | foreach my $default (@defaults) { | 
| 40 | 5 | 100 |  |  |  | 10 | $default = $default->($context, $proto) if isa_coderef($default); | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 4 | 100 |  |  |  | 14 | $proto->params->add($name, @defaults == 1 ? $defaults[0] : [@defaults]); | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 1009 |  |  |  |  | 2077 | return $self; | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | 1; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | __END__ |