| 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'
MC/DC100%1/1
$args{"prefix"} //= ref($self->app) . '::DB'
$args{"prefix"}
Truth table100%2/2
A
A= $args{"prefix"}
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | my @source = | ||||||||||||||||||||||||||||
| 19 | ref( $args{source} ) eq 'ARRAY' | ||||||||||||||||||||||||||||
| 20 | 4 | ? @{ $args{source} } | |||||||||||||||||||||||||||
| 21 | 4 | ▶ | : ( $args{source} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | Rose::DB->default_domain( $args{default_domain} ) if $args{default_domain}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$ENV{"KELP_RDBO_PRELOAD"} or $args{"preload"}
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"}
| |||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Return class only | ||||||||||||||||||||||||||||
| 69 | 13 | return $class; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 4 | ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||