| 1 | package Class::DBI::Loader::Kinship; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base 'Class::DBI::Loader'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Class::DBI::Loader::k_Pg ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | ## Class::DBI::Loader::k_Pg is masquerading as Class::DBI::Loader::Pg | ||||||||||||||||||||||||||||
| 9 | 2 | $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 | 2 | ▶ | use Class::DBI::Loader::Generic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package Class::DBI::Loader::Generic; | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my %kinships ; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub _has_a_many { | ||||||||||||||||||||||||||
|
Subroutine
_has_a_many: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 23 | 0 | my ( $self, $fk_tn, $fk_cn, $uk_tn, $uk_cn ) = @_; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $fk_class = $self->find_class($fk_tn) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $uk_class = $self->find_class($uk_tn) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | my $mn= lc $fk_class . 's'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | warn qq/\# Has_a relationship\n/ if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | my $hasa = "$fk_class ->has_a ( $fk_cn, $uk_class )"; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | warn "$hasa \n\n" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | push @{$kinships{ $fk_class }{has_a}} , $hasa ; | |||||||||||||||||||||||||||
| 32 | 0 | $fk_class -> has_a( $fk_cn, $uk_class ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | warn qq/\# Has_many relationship\n/ if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | my $many = "$uk_class ->has_many ( $mn,$fk_class,$fk_cn )"; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | warn "$many \n\n" if $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | push @{$kinships{ $uk_class }{has_many}} , $many ; | |||||||||||||||||||||||||||
| 38 | 0 | $uk_class -> has_many( $mn, $fk_class, $fk_cn ) ; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _relationships { | ||||||||||||||||||||||||||
|
Subroutine
_relationships: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $ns = $self->{_namespace}||'public' ; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'_namespace'} || 'public'
MC/DC0%0/1
$self->{'_namespace'} || 'public'
$self->{'_namespace'}
Truth table0%0/2
A
A= $self->{'_namespace'}
| |||||||||||||||||||||||||||||
| 44 | 0 | foreach my $table ( $self->tables ) { | |||||||||||||||||||||||||||
| 45 | 0 | my $dbh = $self->find_class($table)->db_Main; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( my $sth = $dbh->foreign_key_info( '', $ns, '', '',$ns, $table) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | for my $res ( @{ $sth->fetchall_arrayref( {} ) } ) { | |||||||||||||||||||||||||||
| 48 | 0 | my $fk_tn = $res->{ FK_TABLE_NAME }; | |||||||||||||||||||||||||||
| 49 | 0 | my $fk_cn = $res->{ FK_COLUMN_NAME }; | |||||||||||||||||||||||||||
| 50 | 0 | my $uk_tn = $res->{ UK_TABLE_NAME }; | |||||||||||||||||||||||||||
| 51 | 0 | my $uk_cn = $res->{ UK_COLUMN_NAME }; | |||||||||||||||||||||||||||
| 52 | 0 | eval { $self->_has_a_many( $fk_tn, $fk_cn, $uk_tn, $uk_cn) }; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | warn qq/\# has_a_many failed "$@"\n\n/ if $@ && $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and $self->debug
MC/DC0%0/2
$@ and $self->debug
$@
$self->debug
Truth table0%0/3
A and B
A= $@B= $self->debug
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub kinships { | ||||||||||||||||||||||||||
|
Subroutine
kinships: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $class, $kind) = @_ ; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | return \%kinships unless $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | { all => $kinships{ $class } , | ||||||||||||||||||||||||||||
| 63 | has_a => $kinships{ $class }{ has_a }, | ||||||||||||||||||||||||||||
| 64 | has_many => $kinships{ $class }{ has_many }, | ||||||||||||||||||||||||||||
| 65 | '' => $kinships{ $class } | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | }->{lc $kind||''}; | ||||||||||||||||||||||||||
|
Condition0%0/2
lc $kind || ''
MC/DC0%0/1
lc $kind || ''
lc $kind
Truth table0%0/2
A
A= lc $kind
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||