|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package FormValidator::Simple::ProfileManager::YAML;  | 
| 
2
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
108873
 | 
 use strict;  | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
    | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
171
 | 
    | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
 
 | 
25
 | 
 use vars qw($VERSION);  | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3714
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 $VERSION = '0.06';  | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
8
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
  
1
  
 | 
736
 | 
     my $class = shift;  | 
| 
9
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     my $self = bless {}, $class;  | 
| 
10
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
     $self->init(@_);  | 
| 
11
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
104375
 | 
     $self;  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub init {  | 
| 
15
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
  
0
  
 | 
11
 | 
     my ($self, $yaml, $options) = @_;  | 
| 
16
 | 
4
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
38
 | 
     $options ||= {};  | 
| 
17
 | 
4
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
26
 | 
     my $loader = $options->{loader} || 'YAML';  | 
| 
18
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
24
 | 
     if ( $loader eq 'YAML::Syck') {  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         require YAML::Syck;  | 
| 
20
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         $self->{_profile} = YAML::Syck::LoadFile($yaml);  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } elsif ( $loader eq 'YAML' ) {  | 
| 
22
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3116
 | 
         require YAML;  | 
| 
23
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25930
 | 
         $self->{_profile} = YAML::LoadFile($yaml);  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
25
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         die "Don't know loader $loader.";  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub extract {  | 
| 
30
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
2491
 | 
     my $self = shift;  | 
| 
31
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
36
 | 
     my $self_new = bless { %$self }, ref $self;  | 
| 
32
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25
 | 
     $self_new->{_profile} = $self_new->get_profile(@_);  | 
| 
33
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
26
 | 
     return unless $self_new->{_profile};  | 
| 
34
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
     return $self_new;  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub get_profile {  | 
| 
38
 | 
29
 | 
 
 | 
 
 | 
  
29
  
 | 
  
1
  
 | 
8349
 | 
     my ($self, @paths) = @_;  | 
| 
39
 | 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
49
 | 
     @paths = map { split /\./ } @paths;  | 
| 
 
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
131
 | 
    | 
| 
40
 | 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
83
 | 
     return $self->_get_profile_recursive($self->{_profile}, @paths);  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _get_profile_recursive {  | 
| 
44
 | 
72
 | 
 
 | 
 
 | 
  
72
  
 | 
 
 | 
120
 | 
     my ($self, $profile, @paths) = @_;  | 
| 
45
 | 
72
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
132
 | 
     if ( @paths ) {  | 
| 
46
 | 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
80
 | 
         $profile = $profile->{shift @paths};  | 
| 
47
 | 
44
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
144
 | 
         return $profile ? $self->_get_profile_recursive($profile, @paths) : undef;  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
49
 | 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
121
 | 
         return $profile;  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub add_profile {  | 
| 
54
 | 
4
 | 
 
 | 
 
 | 
  
4
  
 | 
  
1
  
 | 
2220
 | 
     my $self = shift;  | 
| 
55
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
     my ($keys, $constraint, @paths) = @_;  | 
| 
56
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
     my $prof = $self->get_profile(@paths);  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
     my $key = $self->_get_key($keys);  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # check key duplication. replace constraint if key already exists.  | 
| 
61
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my $key_exists;  | 
| 
62
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
     for (my $i=0; $i< @$prof; $i+=2) {  | 
| 
63
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
         my $cur_key = $self->_get_key($prof->[$i]);  | 
| 
64
 | 
15
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
53
 | 
         if ( $key eq $cur_key ) {  | 
| 
65
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
             $prof->[$i+1] = $constraint;  | 
| 
66
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
             $key_exists++;  | 
| 
67
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
             last;  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # push profile unless keys eixsts  | 
| 
71
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     unless ( $key_exists ) {  | 
| 
72
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         push @$prof, $keys, $constraint;  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub remove_profile {  | 
| 
78
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
0
 | 
     my $self = shift;  | 
| 
79
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my ($keys, @paths) = @_;  | 
| 
80
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $prof = $self->get_profile(@paths);  | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
82
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     my $key = $self->_get_key($keys);  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
     for (my $i=0; $i< @$prof; $i+=2) {  | 
| 
85
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         my $cur_key = $self->_get_key($prof->[$i]);  | 
| 
86
 | 
0
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         if ( $key eq $cur_key ) {  | 
| 
87
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             splice (@$prof, $i, 2);  | 
| 
88
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             last;  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _get_key {  | 
| 
95
 | 
39
 | 
 
 | 
 
 | 
  
39
  
 | 
 
 | 
127
 | 
     my ($self,$keys) = @_;  | 
| 
96
 | 
39
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
80
 | 
     if ( my $ref = ref $keys ) {  | 
| 
97
 | 
8
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
15
 | 
         if ( $ref eq 'HASH') {  | 
| 
98
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
28
 | 
             return (keys %$keys)[0];  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } else {  | 
| 
100
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             die "keys must be a hashref or single scalar.";  | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     } else {  | 
| 
103
 | 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
         return $keys;  | 
| 
104
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
109
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |