| 1 | #======================================================================== | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Badger::Data::Facets | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | # Factory for Badger::Data::Facets validation objects. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||||||||||
| 9 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | #======================================================================== | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | package Badger::Data::Facets; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Badger::Factory::Class | ||||||||||||||||||||||||||||
| 16 | 7 | ▶ | version => 0.01, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | debug => 0, | ||||||||||||||||||||||||||||
| 18 | item => 'facet', | ||||||||||||||||||||||||||||
| 19 | path => 'Badger::Data::Facet BadgerX::Data::Facet', | ||||||||||||||||||||||||||||
| 20 | 7 | constants => 'HASH DOT'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 7 | our $PREFIXES = { | |||||||||||||||||||||||||||
| 24 | text => 'text', | ||||||||||||||||||||||||||||
| 25 | number => 'number', | ||||||||||||||||||||||||||||
| 26 | list => 'list', | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 20 | ▶ | sub type_args { | ||||||||||||||||||||||||||
|
Subroutine
type_args: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 20 | my $type = shift; # my $save = $type; # tmp debug | |||||||||||||||||||||||||||
| 33 | 20 | my $name = $type; | |||||||||||||||||||||||||||
| 34 | 20 | my $base; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # See if we recognise the initial XXX_ prefix as a short-cut. | ||||||||||||||||||||||||||||
| 37 | # If so then the part afterwords is the name we're interested in, | ||||||||||||||||||||||||||||
| 38 | # e.g. text_max_length becomes 'text.max_length' which the factory | ||||||||||||||||||||||||||||
| 39 | # module will map to '<path>::Text::MaxLength' for loading, while | ||||||||||||||||||||||||||||
| 40 | # 'max_length' is the name that we'll use as a default argument name. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 20 | ▶ | if ($type =~ s/^([^\W_]+)(\.|_)(.*)/$3/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 17 | ▶ | if ($2 eq DOT) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 12 | $type = $1.DOT.$type; | |||||||||||||||||||||||||||
| 45 | 12 | $name = $3; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | elsif ($base = $PREFIXES->{ $1 }) { | ||||||||||||||||||||||||||||
| 48 | 5 | $type = $base.DOT.$type; | |||||||||||||||||||||||||||
| 49 | 5 | $name = $3; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||
| 52 | 0 | $type = $1.$2.$type; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 20 | ▶ | my $args = @_ && ref $_[0] eq HASH ? shift : { $name => shift }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ and ref $_[0] eq "HASH"
MC/DC50%1/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # $self->debug("save:$save / type:$type / base:$base / name:$name"); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 20 | return ($type, $args); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||