line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Loader::Kinship; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
57932
|
use 5.008008; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
141
|
|
4
|
2
|
|
|
2
|
|
15
|
use base 'Class::DBI::Loader'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2350
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
3532
|
use Class::DBI::Loader::k_Pg ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
## Class::DBI::Loader::k_Pg is masquerading as Class::DBI::Loader::Pg |
9
|
|
|
|
|
|
|
$INC{'Class/DBI/Loader/Pg.pm'} = '::k_Pg masquerades in its place'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# load Class::DBI::Loader::Generic here to prevent |
12
|
|
|
|
|
|
|
# someone loading later (and redefine our subs) . |
13
|
|
|
|
|
|
|
use Class::DBI::Loader::Generic; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Class::DBI::Loader::Generic; |
16
|
|
|
|
|
|
|
use strict; |
17
|
|
|
|
|
|
|
use warnings; |
18
|
|
|
|
|
|
|
no warnings 'redefine'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %kinships ; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _has_a_many { |
23
|
|
|
|
|
|
|
my ( $self, $fk_tn, $fk_cn, $uk_tn, $uk_cn ) = @_; |
24
|
|
|
|
|
|
|
my $fk_class = $self->find_class($fk_tn) or return; |
25
|
|
|
|
|
|
|
my $uk_class = $self->find_class($uk_tn) or return; |
26
|
|
|
|
|
|
|
my $mn= lc $fk_class . 's'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
warn qq/\# Has_a relationship\n/ if $self->debug; |
29
|
|
|
|
|
|
|
my $hasa = "$fk_class ->has_a ( $fk_cn, $uk_class )"; |
30
|
|
|
|
|
|
|
warn "$hasa \n\n" if $self->debug; |
31
|
|
|
|
|
|
|
push @{$kinships{ $fk_class }{has_a}} , $hasa ; |
32
|
|
|
|
|
|
|
$fk_class -> has_a( $fk_cn, $uk_class ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
warn qq/\# Has_many relationship\n/ if $self->debug; |
35
|
|
|
|
|
|
|
my $many = "$uk_class ->has_many ( $mn,$fk_class,$fk_cn )"; |
36
|
|
|
|
|
|
|
warn "$many \n\n" if $self->debug; |
37
|
|
|
|
|
|
|
push @{$kinships{ $uk_class }{has_many}} , $many ; |
38
|
|
|
|
|
|
|
$uk_class -> has_many( $mn, $fk_class, $fk_cn ) ; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _relationships { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
my $ns = $self->{_namespace}||'public' ; |
44
|
|
|
|
|
|
|
foreach my $table ( $self->tables ) { |
45
|
|
|
|
|
|
|
my $dbh = $self->find_class($table)->db_Main; |
46
|
|
|
|
|
|
|
if ( my $sth = $dbh->foreign_key_info( '', $ns, '', '',$ns, $table) ) { |
47
|
|
|
|
|
|
|
for my $res ( @{ $sth->fetchall_arrayref( {} ) } ) { |
48
|
|
|
|
|
|
|
my $fk_tn = $res->{ FK_TABLE_NAME }; |
49
|
|
|
|
|
|
|
my $fk_cn = $res->{ FK_COLUMN_NAME }; |
50
|
|
|
|
|
|
|
my $uk_tn = $res->{ UK_TABLE_NAME }; |
51
|
|
|
|
|
|
|
my $uk_cn = $res->{ UK_COLUMN_NAME }; |
52
|
|
|
|
|
|
|
eval { $self->_has_a_many( $fk_tn, $fk_cn, $uk_tn, $uk_cn) }; |
53
|
|
|
|
|
|
|
warn qq/\# has_a_many failed "$@"\n\n/ if $@ && $self->debug; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub kinships { |
60
|
|
|
|
|
|
|
my ($self, $class, $kind) = @_ ; |
61
|
|
|
|
|
|
|
return \%kinships unless $class; |
62
|
|
|
|
|
|
|
{ all => $kinships{ $class } , |
63
|
|
|
|
|
|
|
has_a => $kinships{ $class }{ has_a }, |
64
|
|
|
|
|
|
|
has_many => $kinships{ $class }{ has_many }, |
65
|
|
|
|
|
|
|
'' => $kinships{ $class } |
66
|
|
|
|
|
|
|
}->{lc $kind||''}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |