line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Badger::Data::Facet |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Base class validation facet for simple data types. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHOR |
9
|
|
|
|
|
|
|
# Andy Wardley |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
#======================================================================== |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Badger::Data::Facet; |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
24
|
use Badger::Debug ':dump'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
39
|
|
16
|
|
|
|
|
|
|
use Badger::Class |
17
|
4
|
|
|
|
|
29
|
version => 0.01, |
18
|
|
|
|
|
|
|
debug => 0, |
19
|
|
|
|
|
|
|
base => 'Badger::Base', |
20
|
|
|
|
|
|
|
import => 'class', |
21
|
|
|
|
|
|
|
words => 'ARGS OPTS', |
22
|
|
|
|
|
|
|
accessors => 'value', |
23
|
|
|
|
|
|
|
messages => { |
24
|
|
|
|
|
|
|
# invalid => 'Invalid %s. %s', |
25
|
|
|
|
|
|
|
# list_length => '%s should be %d elements long (got %d)', |
26
|
|
|
|
|
|
|
# list_too_short => '%s should be at least %d elements long (got %d)', |
27
|
|
|
|
|
|
|
# list_too_long => '%s should be at most %d elements long (got %d)', |
28
|
|
|
|
|
|
|
# text_length => '%s should be %d characters long (got %d)', |
29
|
|
|
|
|
|
|
# text_too_short => '%s should be at least %d characters long (got %d)', |
30
|
|
|
|
|
|
|
# text_too_long => '%s should be at most %d characters long (got %d)', |
31
|
|
|
|
|
|
|
# too_small => '%s should be no less than %d (got %d)', |
32
|
|
|
|
|
|
|
# too_large => '%s should be no more than %d (got %d)', |
33
|
|
|
|
|
|
|
# pattern => '%s does not match pattern: %s', |
34
|
|
|
|
|
|
|
not_any => '%s does not match any of the permitted values: <3>', |
35
|
|
|
|
|
|
|
# whitespace => 'Invalid whitespace option: %s (expected one of: %s)', |
36
|
|
|
|
|
|
|
# not_number => '%s is not a number: <3>', |
37
|
4
|
|
|
4
|
|
24
|
}; |
|
4
|
|
|
|
|
17
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub init { |
41
|
20
|
|
|
20
|
1
|
33
|
my ($self, $config) = @_; |
42
|
20
|
|
|
|
|
61
|
my $class = $self->class; |
43
|
20
|
|
|
|
|
32
|
my ($option, @optional); |
44
|
|
|
|
|
|
|
|
45
|
20
|
|
|
|
|
24
|
$self->debug("init() config is ", $self->dump_data($config)) if DEBUG; |
46
|
|
|
|
|
|
|
|
47
|
20
|
|
|
|
|
48
|
foreach $option ($class->list_vars(ARGS)) { |
48
|
|
|
|
|
|
|
$self->{ $option } = defined $config->{ $option } |
49
|
17
|
50
|
|
|
|
97
|
? $config->{ $option } |
50
|
|
|
|
|
|
|
: $self->error_msg( missing => $option ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
20
|
|
|
|
|
56
|
@optional = $class->list_vars(OPTS); |
54
|
20
|
|
|
|
|
46
|
@$self{ @optional } = @$config{ @optional }; |
55
|
|
|
|
|
|
|
|
56
|
20
|
|
33
|
|
|
82
|
$self->{ name } ||= do { |
57
|
20
|
|
|
|
|
31
|
my $pkg = ref $self; |
58
|
20
|
|
|
|
|
90
|
$pkg =~ /.*::(\w+)$/; |
59
|
20
|
|
|
|
|
78
|
$1; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
20
|
|
|
|
|
48
|
return $self; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub validate { |
67
|
0
|
|
|
0
|
1
|
0
|
shift->not_implemented; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub invalid { |
72
|
10
|
|
|
10
|
1
|
54
|
shift->error(@_); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub invalid_msg { |
77
|
10
|
|
|
10
|
1
|
18
|
my $self = shift; |
78
|
10
|
|
|
|
|
46
|
$self->invalid( $self->message( @_ ) ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |