blib/lib/Kelp/Module/RDBO.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 75.0% 9 / 12 Conditioncond 75.0% 6 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 92.3% 12 / 13 Podpod 100% 1 / 1 totaltotal 89.6% 87 / 97 CC 11 SCAR 13.4
CC
11
Cov
92%
build
8.1
__ANON__
3.0
__ANON__
2.0
CRAP 3.8
↑ Summary
1 package Kelp::Module::RDBO;
2 4 ▶use Kelp::Base 'Kelp::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Rose::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Rose::DB::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Module::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Digest::MD5 'md5_base64';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our $VERSION = 0.205;
11  
12 4 ▶sub build {
Subroutine build: called CC=8 SCAR=20.9
Pod documented
13 4 my ( $self, %args ) = @_;
14  
15 # Set default prefix to AppName::DB
16 4 ▶ $args{prefix} //= ref( $self->app ) . '::DB';
Condition100%2/2
$args{"prefix"} //= ref($self->app) . '::DB'
l!l
31
MC/DC100%1/1
$args{"prefix"} //= ref($self->app) . '::DB'
$args{"prefix"}
Truth table100%2/2
A
A= $args{"prefix"}
Aresult
11
00
17  
18 my @source =
19 ref( $args{source} ) eq 'ARRAY'
20 4 ? @{ $args{source} }
21 4 ▶ : ( $args{source} );
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'source'} eq 'ARRAY' ? : 4 0 4
22  
23 4 Rose::DB->register_db(%$_) for @source;
24 4 ▶ Rose::DB->default_type( $args{default_type} ) if $args{default_type};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"default_type"} 4 0 4
25 4 ▶ Rose::DB->default_domain( $args{default_domain} ) if $args{default_domain};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"default_domain"} 0 4 4
26  
27 # Insert the app into Rose::DB::Object
28 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 0 ▶ *{"Rose::DB::Object::app"} = sub { $self->app };
Subroutine __ANON__: not called CC=1 SCAR=0.4
30  
31 # Preload all modules, if requested
32 4 ▶ if ( $ENV{KELP_RDBO_PRELOAD} || $args{preload} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"KELP_RDBO_PRELOAD"} or $args{"preload"}) 1 3 4
Condition66%2/3
$ENV{"KELP_RDBO_PRELOAD"} or $args{"preload"}
l!l&&r!l&&!r
013
MC/DC50%1/2
$ENV{"KELP_RDBO_PRELOAD"} or $args{"preload"}
$ENV{"KELP_RDBO_PRELOAD"} $args{"preload"}
Truth table66%2/3
A or B
A= $ENV{"KELP_RDBO_PRELOAD"}B= $args{"preload"}
ABresult
1X1
011
000
33 1 useall $args{prefix};
34 }
35  
36 # Parameters and cache for the rdb closure
37 4 my %rdb_cache = ();
38 4 my @rdb_params = ();
39 24 ▶ my $rdb_code = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
40 24 my $key = md5_base64( join( ':', @rdb_params ) );
41 24 ▶ my $db = $rdb_cache{$key} //= Rose::DB->new(@rdb_params);
Condition66%2/3
$rdb_cache{$key} //= "Rose::DB"->new(@rdb_params)
l!l&&r!l&&!r
2130
MC/DC0%0/2
$rdb_cache{$key} //= "Rose::DB"->new(@rdb_params)
$rdb_cache{$key} "Rose::DB"->new(@rdb_params)
Truth table66%2/3
A //= B
A= $rdb_cache{$key}B= "Rose::DB"->new(@rdb_params)
ABresult
1X1
011
000
42 24 @rdb_params = ();
43 24 return $db;
44 4 };
45  
46 $self->register(
47 4 ▶ rdb => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 4 shift;
49 4 @rdb_params = @_;
50 4 return $rdb_code->();
51 },
52  
53 13 ▶ rdbo => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
54 13 my ( $app, $name, @params ) = @_;
55 13 @rdb_params = @params;
56  
57 # Load the class
58 13 my $full_name = $args{prefix} . '::' . $name;
59 13 ▶ my $class =
Branch: 1 branch
BranchTrueFalseTotal
'Class::Inspector'->loaded($full_name) ? : 10 3 13
60 Class::Inspector->loaded($full_name)
61 ? $full_name
62 : Plack::Util::load_class($full_name);
63  
64 # Insert an init_db method, if none found
65 13 my $glob = "${class}::init_db";
66 13 ▶ *{$glob} = $rdb_code unless ( *{$glob}{CODE} );
Branch: 1 branch
BranchTrueFalseTotal
unless *{$glob;}{"CODE"} 7 6 13
67  
68 # Return class only
69 13 return $class;
70 }
71 4 );
72 }
73  
74 4 1;
75  
76 __END__
↑ Summary