| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # Configuration Class for Validation Classes | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Validation::Class::Configuration provides a default configuration profile used | 
| 4 |  |  |  |  |  |  | # by validation classes and many class prototype methods. | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | package Validation::Class::Configuration; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 108 |  |  | 108 |  | 568 | use strict; | 
|  | 108 |  |  |  |  | 1348 |  | 
|  | 108 |  |  |  |  | 4983 |  | 
| 9 | 108 |  |  | 108 |  | 1624 | use warnings; | 
|  | 108 |  |  |  |  | 195 |  | 
|  | 108 |  |  |  |  | 7296 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 108 |  |  | 108 |  | 72373 | use Validation::Class::Directives; | 
|  | 108 |  |  |  |  | 336 |  | 
|  | 108 |  |  |  |  | 4672 |  | 
| 12 | 108 |  |  | 108 |  | 60305 | use Validation::Class::Listing; | 
|  | 108 |  |  |  |  | 296 |  | 
|  | 108 |  |  |  |  | 3103 |  | 
| 13 | 108 |  |  | 108 |  | 669 | use Validation::Class::Mapping; | 
|  | 108 |  |  |  |  | 207 |  | 
|  | 108 |  |  |  |  | 2575 |  | 
| 14 | 108 |  |  | 108 |  | 56057 | use Validation::Class::Fields; | 
|  | 108 |  |  |  |  | 325 |  | 
|  | 108 |  |  |  |  | 3342 |  | 
| 15 | 108 |  |  | 108 |  | 61665 | use Validation::Class::Mixins; | 
|  | 108 |  |  |  |  | 332 |  | 
|  | 108 |  |  |  |  | 3240 |  | 
| 16 | 108 |  |  | 108 |  | 715 | use Validation::Class::Util; | 
|  | 108 |  |  |  |  | 260 |  | 
|  | 108 |  |  |  |  | 517 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 108 |  |  | 108 |  | 586 | use Module::Find 'usesub'; | 
|  | 108 |  |  |  |  | 216 |  | 
|  | 108 |  |  |  |  | 116124 |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | our $VERSION = '7.900057'; # VERSION | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub attributes { | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 179 |  |  | 179 | 0 | 395 | my ($self) = @_; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 179 |  |  |  |  | 533 | return $self->profile->{ATTRIBUTES}; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub builders { | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 169 |  |  | 169 | 0 | 359 | my ($self) = @_; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 169 |  |  |  |  | 568 | return $self->profile->{BUILDERS}; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub configure_profile { | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 316 |  |  | 316 | 0 | 629 | my ($self) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 316 |  |  |  |  | 995 | $self->configure_profile_register_directives; | 
| 43 | 316 |  |  |  |  | 1009 | $self->configure_profile_register_filters; | 
| 44 | 316 |  |  |  |  | 971 | $self->configure_profile_register_events; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 316 |  |  |  |  | 1137 | return $self; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub configure_profile_register_directives { | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 316 |  |  | 316 | 0 | 570 | my ($self) = @_; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # automatically attach discovered directive classes | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 316 |  |  |  |  | 1897 | my $directives = Validation::Class::Directives->new; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 316 |  |  |  |  | 1563 | foreach my $directive ($directives->values) { | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 14536 |  |  |  |  | 39342 | my $name = $directive->name; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 14536 |  |  |  |  | 31876 | $self->directives->add($name => $directive); | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 316 |  |  |  |  | 5285 | return $self; | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub configure_profile_register_filters { | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 316 |  |  | 316 | 0 | 587 | my ($self) = @_; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | # automatically attach filters registered on in the filters directive | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 316 |  |  |  |  | 794 | my $directives = $self->directives; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 316 |  |  |  |  | 1223 | my $filters = $directives->get('filters'); | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 316 | 50 |  |  |  | 1013 | return unless $filters; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 316 |  |  |  |  | 1027 | $self->filters->add($filters->registry); | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 316 |  |  |  |  | 782 | return $self; | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub configure_profile_register_events { | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 316 |  |  | 316 | 0 | 588 | my ($self) = @_; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # inspect the directives for event subscriptions | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 316 | 50 |  |  |  | 881 | if (my @directives = ($self->directives->values)) { | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 316 |  |  |  |  | 1606 | my $events = { | 
| 97 |  |  |  |  |  |  | # hookable events list, keyed by directive name | 
| 98 |  |  |  |  |  |  | 'on_after_validation'   => {}, | 
| 99 |  |  |  |  |  |  | 'on_before_validation'  => {}, | 
| 100 |  |  |  |  |  |  | 'on_normalize'          => {}, | 
| 101 |  |  |  |  |  |  | 'on_validate'           => {} | 
| 102 |  |  |  |  |  |  | }; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 316 |  |  |  |  | 648 | while (my($name, $container) = each(%{$events})) { | 
|  | 1580 |  |  |  |  | 5541 |  | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 1264 |  |  |  |  | 5009 | ($name) = $name =~ /^on_(\w+)/; | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 1264 |  |  |  |  | 2503 | foreach my $directive (@directives) { | 
| 109 | 58156 | 50 |  |  |  | 124082 | next if defined $container->{$name}; | 
| 110 | 58156 | 100 |  |  |  | 249454 | if (my $routine = $directive->can($name)) { | 
| 111 | 21491 |  |  |  |  | 55354 | $container->{$directive->name} = $routine; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 316 |  |  |  |  | 1153 | $self->events->add($events); | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 316 |  |  |  |  | 4313 | return $self; | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | sub default_profile { | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 151 |  |  | 151 | 0 | 1762 | my %default_mixins = ( | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | ':flg' => Validation::Class::Mixin->new( | 
| 130 |  |  |  |  |  |  | required    => 1, | 
| 131 |  |  |  |  |  |  | min_length  => 1, | 
| 132 |  |  |  |  |  |  | filters     => [qw/trim strip numeric/], | 
| 133 |  |  |  |  |  |  | between     => [0, 1], | 
| 134 |  |  |  |  |  |  | name        => ':flg', | 
| 135 |  |  |  |  |  |  | ), | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | ':num' => Validation::Class::Mixin->new( | 
| 138 |  |  |  |  |  |  | required    => 1, | 
| 139 |  |  |  |  |  |  | min_length  => 1, | 
| 140 |  |  |  |  |  |  | filters     => [qw/trim strip numeric/], | 
| 141 |  |  |  |  |  |  | name        => ':num', | 
| 142 |  |  |  |  |  |  | ), | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | ':str'  => Validation::Class::Mixin->new( | 
| 145 |  |  |  |  |  |  | required    => 1, | 
| 146 |  |  |  |  |  |  | min_length  => 1, | 
| 147 |  |  |  |  |  |  | filters     => [qw/trim strip/], | 
| 148 |  |  |  |  |  |  | name        => ':str', | 
| 149 |  |  |  |  |  |  | ) | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | ); | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 151 |  |  |  |  | 844 | return Validation::Class::Mapping->new({ | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | ATTRIBUTES  => Validation::Class::Mapping->new, | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | BUILDERS    => Validation::Class::Listing->new, | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | DIRECTIVES  => Validation::Class::Mapping->new, | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | DOCUMENTS   => Validation::Class::Mapping->new, | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | EVENTS     => Validation::Class::Mapping->new, | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | FIELDS     => Validation::Class::Fields->new, | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | FILTERS    => Validation::Class::Mapping->new, | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | METHODS    => Validation::Class::Mapping->new, | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | MIXINS     => Validation::Class::Mixins->new(%default_mixins), | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | PROFILES   => Validation::Class::Mapping->new, | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | SETTINGS   => Validation::Class::Mapping->new, | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | }); | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | } | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | sub directives { | 
| 182 |  |  |  |  |  |  |  | 
| 183 | 15336 |  |  | 15336 | 0 | 20409 | my ($self) = @_; | 
| 184 |  |  |  |  |  |  |  | 
| 185 | 15336 |  |  |  |  | 28465 | return $self->profile->{DIRECTIVES}; | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | sub documents { | 
| 190 |  |  |  |  |  |  |  | 
| 191 | 177 |  |  | 177 | 0 | 422 | my ($self) = @_; | 
| 192 |  |  |  |  |  |  |  | 
| 193 | 177 |  |  |  |  | 550 | return $self->profile->{DOCUMENTS}; | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | } | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | sub events { | 
| 198 |  |  |  |  |  |  |  | 
| 199 | 481 |  |  | 481 | 0 | 821 | my ($self) = @_; | 
| 200 |  |  |  |  |  |  |  | 
| 201 | 481 |  |  |  |  | 1186 | return $self->profile->{EVENTS}; | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | } | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | sub fields { | 
| 206 |  |  |  |  |  |  |  | 
| 207 | 319 |  |  | 319 | 0 | 593 | my ($self) = @_; | 
| 208 |  |  |  |  |  |  |  | 
| 209 | 319 |  |  |  |  | 864 | return $self->profile->{FIELDS}; | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | } | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | sub filters { | 
| 214 |  |  |  |  |  |  |  | 
| 215 | 482 |  |  | 482 | 0 | 775 | my ($self) = @_; | 
| 216 |  |  |  |  |  |  |  | 
| 217 | 482 |  |  |  |  | 1118 | return $self->profile->{FILTERS}; | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | } | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | sub methods { | 
| 222 |  |  |  |  |  |  |  | 
| 223 | 184 |  |  | 184 | 0 | 422 | my ($self) = @_; | 
| 224 |  |  |  |  |  |  |  | 
| 225 | 184 |  |  |  |  | 581 | return $self->profile->{METHODS}; | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | } | 
| 228 |  |  |  |  |  |  |  | 
| 229 |  |  |  |  |  |  | sub mixins { | 
| 230 |  |  |  |  |  |  |  | 
| 231 | 184 |  |  | 184 | 0 | 435 | my ($self) = @_; | 
| 232 |  |  |  |  |  |  |  | 
| 233 | 184 |  |  |  |  | 581 | return $self->profile->{MIXINS}; | 
| 234 |  |  |  |  |  |  |  | 
| 235 |  |  |  |  |  |  | } | 
| 236 |  |  |  |  |  |  |  | 
| 237 |  |  |  |  |  |  | sub new { | 
| 238 |  |  |  |  |  |  |  | 
| 239 | 151 |  |  | 151 | 0 | 465 | my $self = bless {}, shift; | 
| 240 |  |  |  |  |  |  |  | 
| 241 | 151 |  |  |  |  | 676 | $self->configure_profile; | 
| 242 |  |  |  |  |  |  |  | 
| 243 | 151 |  |  |  |  | 918 | return $self; | 
| 244 |  |  |  |  |  |  |  | 
| 245 |  |  |  |  |  |  | } | 
| 246 |  |  |  |  |  |  |  | 
| 247 |  |  |  |  |  |  | sub profile { | 
| 248 |  |  |  |  |  |  |  | 
| 249 | 17906 |  |  | 17906 | 0 | 22549 | my ($self) = @_; | 
| 250 |  |  |  |  |  |  |  | 
| 251 | 17906 |  | 66 |  |  | 85102 | return $self->{profile} ||= $self->default_profile; | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | } | 
| 254 |  |  |  |  |  |  |  | 
| 255 |  |  |  |  |  |  | sub profiles { | 
| 256 |  |  |  |  |  |  |  | 
| 257 | 176 |  |  | 176 | 0 | 421 | my ($self) = @_; | 
| 258 |  |  |  |  |  |  |  | 
| 259 | 176 |  |  |  |  | 564 | return $self->profile->{PROFILES}; | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | } | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  | sub settings { | 
| 264 |  |  |  |  |  |  |  | 
| 265 | 197 |  |  | 197 | 0 | 475 | my ($self) = @_; | 
| 266 |  |  |  |  |  |  |  | 
| 267 | 197 |  |  |  |  | 655 | return $self->profile->{SETTINGS}; | 
| 268 |  |  |  |  |  |  |  | 
| 269 |  |  |  |  |  |  | } | 
| 270 |  |  |  |  |  |  |  | 
| 271 |  |  |  |  |  |  | 1; |