line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Plugin::Factory; |
2
|
1
|
|
|
1
|
|
988
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
3
|
1
|
|
|
1
|
|
7
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1612
|
use Class::Inspector; |
|
1
|
|
|
|
|
7117
|
|
|
1
|
|
|
|
|
149
|
|
8
|
1
|
|
|
1
|
|
5526
|
use UNIVERSAL::require; |
|
1
|
|
|
|
|
5374
|
|
|
1
|
|
|
|
|
14
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub import { |
11
|
0
|
|
|
0
|
|
|
my $class = shift; |
12
|
0
|
|
|
|
|
|
my $pkg = caller(0); |
13
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
unless( $pkg->isa('Class::DBI') ){ |
15
|
0
|
|
|
|
|
|
$class->_croak(qq/This plugin is for CDBI application./); |
16
|
|
|
|
|
|
|
} |
17
|
0
|
|
|
|
|
|
$pkg->mk_classdata($_) for qw/type_column _factory_types/; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
107
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
775
|
|
20
|
0
|
|
|
|
|
|
*{$pkg."::set_factory"} = sub { |
21
|
0
|
|
|
0
|
|
|
my($caller, %args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
if ( $args{type_column} ) { |
24
|
0
|
|
|
|
|
|
$caller->type_column( $args{type_column} ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
$caller->_croak(qq/Type column isn't defined./) |
28
|
|
|
|
|
|
|
unless $caller->type_column; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
$caller->_factory_types( $args{types} || {} ); |
31
|
0
|
|
|
|
|
|
$class->_require_modules($caller); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$caller->add_trigger( select => sub { |
34
|
0
|
|
|
|
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
my $type = $self->type_column; |
36
|
0
|
0
|
|
|
|
|
unless( $self->can($type) ) { |
37
|
0
|
|
|
|
|
|
$self->_croak(qq/Couldn't call method "$type"./); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
0
|
|
|
|
my $subclass = $self->_factory_types->{$self->$type} |
40
|
|
|
|
|
|
|
|| $self->_factory_types->{'-Base'}; |
41
|
0
|
0
|
|
|
|
|
unless( Class::Inspector->loaded($subclass) ) { |
42
|
0
|
|
|
|
|
|
$self->_croak(qq/Unknown class "$subclass"./); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
bless $self, $subclass; |
45
|
0
|
|
|
|
|
|
} ); |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _require_modules { |
50
|
0
|
|
|
0
|
|
|
my($class, $pkg) = @_; |
51
|
0
|
|
|
|
|
|
while( my($type, $module) = each %{ $pkg->_factory_types } ) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$module = join "::", $pkg, $module; |
53
|
0
|
0
|
|
|
|
|
unless( Class::Inspector->installed($module) ) { |
54
|
0
|
|
|
|
|
|
$class->_croak(qq/"$module" isn't installed./); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
$module->require; |
57
|
0
|
0
|
|
|
|
|
$class->_croak(qq/Couldn't require "$module", "$@"./) if($@); |
58
|
0
|
|
|
|
|
|
$pkg->_factory_types->{$type} = $module; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _croak { |
63
|
0
|
|
|
0
|
|
|
my($self, $msg) = @_; |
64
|
0
|
|
|
|
|
|
require Carp; Carp::croak($msg); |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |