lib/Badger/Data/Facets.pm

filter: Statementstmt 94.4% 17 / 18 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 2 / 2 Podpod 100% 1 / 1 totaltotal 88.2% 30 / 34 CC 6 SCAR 16.8
CC
6
Cov
90%
type_args
6.1
BEGIN
1.0
CRAP 5.3
« lib/Badger.pm ↑ Summary lib/Badger/Workspace.pm »
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
BranchTrueFalseTotal
if ($type =~ s/^([^\W_]+)(\.|_)(.*)/$3/) 17 3 20
43 17 ▶ if ($2 eq DOT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($2 eq '.') { } 12 5 17
elsif ($base = $Badger::Data::Facets::PREFIXES->{$1}) { } 5 0 5
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
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 5 15 20
Condition66%2/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
0155
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"
ABresult
0X0
100
111
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__
« lib/Badger.pm ↑ Summary lib/Badger/Workspace.pm »