Class/Field.pm

filter: Statementstmt 100% 34 / 34 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 94.4% 51 / 54 CC 3 SCAR 5.3
CC
3
Cov
93%
new
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« Class/Fields.pm ↑ Summary Class/Params.pm »
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
BranchTrueFalseTotal
if (() = each %{$directives;}) 1736 56 1792
20
21 1736 ▶ if ($cfg->{field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->{"field"}) 1736 0 1736
22
23 1736 ▶ next if $dir =~ s/[^a-zA-Z0-9\_]/\_/g;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ s/[^a-zA-Z0-9\_]/_/g 56 1680 1736
24
25 # create accessors from default configuration (once)
26 1680 ▶ has $dir => undef unless grep { $dir eq $_ } qw(errors);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$dir eq $_;} "errors" 1624 56 1680
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
BranchTrueFalseTotal
unless $config->{"name"} 0 170 170
43
44 170 my $self = bless $config, $class;
45
46 170 ▶ delete $self->{errors} if exists $self->{errors};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"errors"} 0 170 170
47
48 170 $self->errors; # initialize if not already
49
50 170 return $self;
51
52 }
53  
54 56 1;
55 __END__
« Class/Fields.pm ↑ Summary Class/Params.pm »