line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kelp::Module::RDBO; |
2
|
3
|
|
|
3
|
|
125068
|
use Kelp::Base 'Kelp::Module'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
22
|
|
3
|
3
|
|
|
3
|
|
11357
|
use Rose::DB; |
|
3
|
|
|
|
|
1198011
|
|
|
3
|
|
|
|
|
113
|
|
4
|
3
|
|
|
3
|
|
4278
|
use Rose::DB::Object; |
|
3
|
|
|
|
|
851518
|
|
|
3
|
|
|
|
|
110
|
|
5
|
3
|
|
|
3
|
|
39
|
use Plack::Util; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
74
|
|
6
|
3
|
|
|
3
|
|
20
|
use Class::Inspector; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
70
|
|
7
|
3
|
|
|
3
|
|
3978
|
use Module::Find; |
|
3
|
|
|
|
|
6441
|
|
|
3
|
|
|
|
|
1371
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.106; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub build { |
12
|
3
|
|
|
3
|
1
|
445
|
my ( $self, %args ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Set default prefix to AppName::DB |
15
|
3
|
|
66
|
|
|
23
|
$args{prefix} //= ref( $self->app ) . '::DB'; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
|
|
12
|
my @source = |
18
|
|
|
|
|
|
|
ref( $args{source} ) eq 'ARRAY' |
19
|
3
|
50
|
|
|
|
24
|
? @{ $args{source} } |
20
|
|
|
|
|
|
|
: ( $args{source} ); |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
41
|
Rose::DB->register_db(%$_) for @source; |
23
|
3
|
50
|
|
|
|
41966
|
Rose::DB->default_type( $args{default_type} ) if $args{default_type}; |
24
|
3
|
50
|
|
|
|
92
|
Rose::DB->default_domain( $args{default_domain} ) if $args{default_domain}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Insert the app into Rose::DB::Object |
27
|
3
|
|
|
3
|
|
26
|
no strict 'refs'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
2354
|
|
28
|
3
|
|
|
0
|
|
21
|
*{"Rose::DB::Object::app"} = sub { $self->app }; |
|
3
|
|
|
|
|
32
|
|
|
0
|
|
|
|
|
0
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Preload all modules, if requested |
31
|
3
|
100
|
66
|
|
|
42
|
if ( $ENV{KELP_RDBO_PRELOAD} || $args{preload} ) { |
32
|
1
|
|
|
|
|
7
|
useall $args{prefix}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->register( |
36
|
|
|
|
|
|
|
rdb => Rose::DB->new, |
37
|
|
|
|
|
|
|
rdbo => sub { |
38
|
6
|
|
|
6
|
|
222089
|
my ( $app, $name ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Load the class |
41
|
6
|
|
|
|
|
34
|
my $full_name = $args{prefix} . '::' . $name; |
42
|
6
|
100
|
|
|
|
55
|
my $class = |
43
|
|
|
|
|
|
|
Class::Inspector->loaded($full_name) |
44
|
|
|
|
|
|
|
? $full_name |
45
|
|
|
|
|
|
|
: Plack::Util::load_class($full_name); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Insert an init_db method, if none found |
48
|
6
|
|
|
|
|
99893
|
my $glob = "${class}::init_db"; |
49
|
5
|
|
|
9
|
|
27
|
*{$glob} = sub { $app->rdb } |
|
9
|
|
|
|
|
2706
|
|
50
|
6
|
100
|
|
|
|
14
|
unless ( *{$glob}{CODE} ); |
|
6
|
|
|
|
|
75
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Return class only |
53
|
6
|
|
|
|
|
131
|
return $class; |
54
|
|
|
|
|
|
|
} |
55
|
3
|
|
|
|
|
58711
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |