| 1 | # ABSTRACT: Field Object for Validation::Class Classes | ||||||||||
| 2 | |||||||||||
| 3 | package Validation::Class::Field; | ||||||||||
| 4 | { | ||||||||||
| 5 | 56 | $Validation::Class::Field::VERSION = '7.10_01'; | |||||||||
| 6 | } | ||||||||||
| 7 | |||||||||||
| 8 | 56 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 56 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 56 | our $VERSION = '7.10_01'; # VERSION | |||||||||
| 12 | |||||||||||
| 13 | 56 | ▶ | use Carp 'confess'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 56 | ▶ | use Validation::Class::Base 'has'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 56 | ▶ | use Validation::Class::Prototype; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 56 | my $directives = Validation::Class::Prototype->configuration->{DIRECTIVES}; | |||||||||
| 18 | |||||||||||
| 19 | 56 | ▶ | while (my($dir, $cfg) = each %{$directives}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 1736 | ▶ | if ($cfg->{field}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 1736 | ▶ | next if $dir =~ s/[^a-zA-Z0-9\_]/\_/g; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | |||||||||||
| 25 | # create accessors from default configuration (once) | ||||||||||
| 26 | 1680 | ▶ | has $dir => undef unless grep { $dir eq $_ } qw(errors); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 170 | ▶ | has 'errors' => sub { Validation::Class::Errors->new }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | sub new { | ||||||||||
| 38 | |||||||||||
| 39 | 170 | ▶ | my ($class, $config) = @_; | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | confess "Can't create a new field object without a name attribute" | ||||||||||
| 42 | 170 | ▶ | unless $config->{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 170 | my $self = bless $config, $class; | |||||||||
| 45 | |||||||||||
| 46 | 170 | ▶ | delete $self->{errors} if exists $self->{errors}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 170 | $self->errors; # initialize if not already | |||||||||
| 49 | |||||||||||
| 50 | 170 | return $self; | |||||||||
| 51 | |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 56 | 1; | |||||||||
| 55 | __END__ | ||||||||||