| 1 | #======================================================================== | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # Badger::Data::Facet | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||
| 6 | # Base class validation facet for simple data types. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||
| 9 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||
| 10 | # | ||||||||||||||||||||
| 11 | #======================================================================== | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | package Badger::Data::Facet; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | ▶ | use Badger::Debug ':dump'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | use Badger::Class | ||||||||||||||||||||
| 17 | 4 | 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 | ▶ | }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub init { | ||||||||||||||||||||
| 41 | 20 | ▶ | my ($self, $config) = @_; | ||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||
| 42 | 20 | my $class = $self->class; | |||||||||||||||||||
| 43 | 20 | my ($option, @optional); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 20 | $self->debug("init() config is ", $self->dump_data($config)) if DEBUG; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 20 | foreach $option ($class->list_vars(ARGS)) { | |||||||||||||||||||
| 48 | $self->{ $option } = defined $config->{ $option } | ||||||||||||||||||||
| 49 | 17 | ▶ | ? $config->{ $option } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | : $self->error_msg( missing => $option ); | ||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 20 | @optional = $class->list_vars(OPTS); | |||||||||||||||||||
| 54 | 20 | @$self{ @optional } = @$config{ @optional }; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 20 | ▶ | $self->{ name } ||= do { | ||||||||||||||||||
|
Condition33%1/3
$self->{"name"} ||= do {
my $pkg = ref $self;
$pkg =~ /.*::(\w+)$/;
$1
}
MC/DC0%0/2
$self->{"name"} ||= do {
my $pkg = ref $self;
$pkg =~ /.*::(\w+)$/;
$1
}
$self->{"name"}
do {
my $pkg = ref $self;
$pkg =~ /.*::(\w+)$/;
$1
}
Truth table33%1/3
A ||= B
A= $self->{"name"}B= do {
my $pkg = ref $self;
$pkg =~ /.*::(\w+)$/;
$1
}
| |||||||||||||||||||||
| 57 | 20 | my $pkg = ref $self; | |||||||||||||||||||
| 58 | 20 | $pkg =~ /.*::(\w+)$/; | |||||||||||||||||||
| 59 | 20 | $1; | |||||||||||||||||||
| 60 | }; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 20 | return $self; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub validate { | ||||||||||||||||||||
| 67 | 0 | ▶ | shift->not_implemented; | ||||||||||||||||||
|
Subroutine
validate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | sub invalid { | ||||||||||||||||||||
| 72 | 10 | ▶ | shift->error(@_); | ||||||||||||||||||
|
Subroutine
invalid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | sub invalid_msg { | ||||||||||||||||||||
| 77 | 10 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
invalid_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 78 | 10 | $self->invalid( $self->message( @_ ) ); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 4 | 1; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||