blib/lib/Badger/Data/Facets.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 33 CC 5 SCAR 32.3
CC
5
Cov
0%
type_args
30.0
BEGIN
2.0
CRAP 25.3
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 version => 0.01,
17 debug => 0,
18 item => 'facet',
19 path => 'Badger::Data::Facet BadgerX::Data::Facet',
20 constants => 'HASH DOT';
21  
22  
23 our $PREFIXES = {
24 text => 'text',
25 number => 'number',
26 list => 'list',
27 };
28  
29  
30 sub type_args {
31 my $self = shift;
32 my $type = shift; # my $save = $type; # tmp debug
33 my $name = $type;
34 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 if ($type =~ s/^([^\W_]+)(\.|_)(.*)/$3/) {
43 if ($2 eq DOT) {
44 $type = $1.DOT.$type;
45 $name = $3;
46 }
47 elsif ($base = $PREFIXES->{ $1 }) {
48 $type = $base.DOT.$type;
49 $name = $3;
50 }
51 else {
52 $type = $1.$2.$type;
53 }
54 }
55  
56 my $args = @_ && ref $_[0] eq HASH ? shift : { $name => shift };
57  
58 # $self->debug("save:$save / type:$type / base:$base / name:$name");
59  
60 return ($type, $args);
61 }
62  
63  
64 1;
65  
66 __END__