line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FormValidator::Simple::Messages; |
2
|
22
|
|
|
22
|
|
167
|
use strict; |
|
22
|
|
|
|
|
47
|
|
|
22
|
|
|
|
|
926
|
|
3
|
22
|
|
|
22
|
|
112
|
use base 'Class::Accessor::Fast'; |
|
22
|
|
|
|
|
902
|
|
|
22
|
|
|
|
|
1618
|
|
4
|
22
|
|
|
22
|
|
19244
|
use YAML; |
|
22
|
|
|
|
|
225605
|
|
|
22
|
|
|
|
|
1477
|
|
5
|
22
|
|
|
22
|
|
243
|
use FormValidator::Simple::Exception; |
|
22
|
|
|
|
|
92
|
|
|
22
|
|
|
|
|
240
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/decode_from/); |
8
|
22
|
|
|
22
|
|
826
|
use Encode; |
|
22
|
|
|
|
|
51
|
|
|
22
|
|
|
|
|
18512
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
23
|
|
|
23
|
1
|
60
|
my $class = shift; |
12
|
23
|
|
|
|
|
117
|
my $self = bless { |
13
|
|
|
|
|
|
|
_data => undef, |
14
|
|
|
|
|
|
|
_format => "%s", |
15
|
|
|
|
|
|
|
}, $class; |
16
|
23
|
|
|
|
|
130
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub format { |
20
|
37
|
|
|
37
|
0
|
106
|
my ($self, $format) = @_; |
21
|
37
|
100
|
|
|
|
70
|
if ($format) { |
22
|
2
|
|
|
|
|
8
|
$self->{_format} = $format; |
23
|
|
|
|
|
|
|
} |
24
|
37
|
|
|
|
|
265
|
$self->{_format}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub load { |
28
|
4
|
|
|
4
|
0
|
60
|
my ($self, $data) = @_; |
29
|
4
|
100
|
33
|
|
|
125
|
if (ref $data eq 'HASH') { |
|
|
50
|
33
|
|
|
|
|
30
|
2
|
|
|
|
|
18
|
$self->{_data} = $data; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif (-e $data && -f _ && -r _) { |
33
|
2
|
|
|
|
|
4
|
eval { |
34
|
2
|
|
|
|
|
15
|
$self->{_data} = YAML::LoadFile($data); |
35
|
|
|
|
|
|
|
}; |
36
|
2
|
50
|
|
|
|
51314
|
if ($@) { |
37
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
38
|
|
|
|
|
|
|
qq/failed to load YAML file. "$@"/ |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
44
|
|
|
|
|
|
|
qq/set hash reference or YAML file path./ |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get { |
50
|
35
|
|
|
35
|
1
|
213
|
my $self = shift; |
51
|
35
|
|
|
|
|
86
|
my $msg = $self->_get(@_); |
52
|
35
|
50
|
66
|
|
|
194
|
if ($self->decode_from && !Encode::is_utf8($msg)) { |
53
|
0
|
|
|
|
|
0
|
$msg = Encode::decode($self->decode_from, $msg); |
54
|
|
|
|
|
|
|
} |
55
|
35
|
|
|
|
|
252
|
return sprintf $self->format, $msg; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _get { |
59
|
35
|
|
|
35
|
|
90
|
my ($self, $action, $name, $type) = @_; |
60
|
35
|
|
|
|
|
60
|
my $data = $self->{_data}; |
61
|
35
|
50
|
|
|
|
73
|
unless ($data) { |
62
|
0
|
|
|
|
|
0
|
FormValidator::Simple::Exception->throw( |
63
|
|
|
|
|
|
|
qq/set messages before calling get()./ |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
35
|
50
|
33
|
|
|
195
|
unless ( $action && exists $data->{$action} ) { |
68
|
0
|
0
|
|
|
|
0
|
if ( exists $data->{DEFAULT} ) { |
69
|
0
|
0
|
|
|
|
0
|
if ( exists $data->{DEFAULT}{$name} ) { |
70
|
0
|
|
|
|
|
0
|
my $conf = $data->{DEFAULT}{$name}; |
71
|
0
|
0
|
|
|
|
0
|
if ( exists $conf->{$type} ) { |
|
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
return $conf->{$type}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ( exists $conf->{DEFAULT} ) { |
75
|
0
|
|
|
|
|
0
|
return $conf->{DEFAULT}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
0
|
return "$name is invalid."; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
0
|
return "$name is invalid."; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
35
|
100
|
33
|
|
|
173
|
if ( exists $data->{$action}{$name} ) { |
|
|
50
|
|
|
|
|
|
87
|
32
|
|
|
|
|
54
|
my $conf = $data->{$action}{$name}; |
88
|
32
|
100
|
0
|
|
|
83
|
if ( exists $conf->{$type} ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
89
|
25
|
|
|
|
|
71
|
return $conf->{$type}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif ( exists $conf->{DEFAULT} ) { |
92
|
7
|
|
|
|
|
26
|
return $conf->{DEFAULT}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( exists $data->{DEFAULT} |
95
|
|
|
|
|
|
|
&& exists $data->{DEFAULT}{$name} ) { |
96
|
0
|
|
|
|
|
0
|
my $conf = $data->{DEFAULT}{$name}; |
97
|
0
|
0
|
|
|
|
0
|
if ( exists $conf->{$type} ) { |
|
|
0
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
return $conf->{$type}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
elsif ( exists $conf->{DEFAULT} ) { |
101
|
0
|
|
|
|
|
0
|
return $conf->{DEFAULT}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
elsif ( exists $data->{DEFAULT} |
106
|
|
|
|
|
|
|
&& exists $data->{DEFAULT}{$name} ) { |
107
|
3
|
|
|
|
|
7
|
my $conf = $data->{DEFAULT}{$name}; |
108
|
3
|
50
|
|
|
|
16
|
if ( exists $conf->{$type} ) { |
|
|
50
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
return $conf->{$type}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( exists $conf->{DEFAULT} ) { |
112
|
3
|
|
|
|
|
8
|
return $conf->{DEFAULT}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return "$name is invalid."; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
__END__ |