Kinship.pm

filter: Statementstmt 42.1% 24 / 57 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 31.9% 31 / 97 CC 15 SCAR 35.4
CC
15
Cov
29%
_has_a_many
56.0
_relationships
56.0
kinships
12.0
CRAP 34.5
↑ Summary k_Pg.pm »
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
BranchTrueFalseTotal
my $fk_class = $self->find_class($fk_tn) or return 0 0 0
25 0 ▶ my $uk_class = $self->find_class($uk_tn) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $uk_class = $self->find_class($uk_tn) or return 0 0 0
26 0 my $mn= lc $fk_class . 's';
27  
28 0 ▶ warn qq/\# Has_a relationship\n/ if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
29 0 my $hasa = "$fk_class ->has_a ( $fk_cn, $uk_class )";
30 0 ▶ warn "$hasa \n\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
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
BranchTrueFalseTotal
if $self->debug 0 0 0
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
BranchTrueFalseTotal
if $self->debug 0 0 0
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'
l!l
00
MC/DC0%0/1
$self->{'_namespace'} || 'public'
$self->{'_namespace'}
Truth table0%0/2
A
A= $self->{'_namespace'}
Aresult
11
00
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
BranchTrueFalseTotal
if (my $sth = $dbh->foreign_key_info("", $ns, "", "", $ns, $table)) 0 0 0
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
BranchTrueFalseTotal
if $@ and $self->debug 0 0 0
Condition0%0/3
$@ and $self->debug
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and $self->debug
$@ $self->debug
Truth table0%0/3
A and B
A= $@B= $self->debug
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $class 0 0 0
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 || ''
l!l
00
MC/DC0%0/1
lc $kind || ''
lc $kind
Truth table0%0/2
A
A= lc $kind
Aresult
11
00
67 }
68  
69  
70 2 1;
71  
72 __END__
↑ Summary k_Pg.pm »