File Coverage

blib/lib/Alzabo/ForeignKey.pm
Criterion Covered Total %
statement 9 50 18.0
branch 0 4 0.0
condition 0 12 0.0
subroutine 3 19 15.7
pod 14 16 87.5
total 26 101 25.7


line stmt bran cond sub pod time code
1             package Alzabo::ForeignKey;
2              
3 11     11   71 use strict;
  11         19  
  11         415  
4 11     11   63 use vars qw($VERSION);
  11         17  
  11         563  
5              
6 11     11   59 use Alzabo;
  11         32  
  11         10099  
7              
8              
9             $VERSION = 2.0;
10              
11             1;
12              
13             sub table_from
14             {
15 0     0 1   my $self = shift;
16              
17 0           return ($self->columns_from)[0]->table;
18             }
19              
20             sub table_to
21             {
22 0     0 1   my $self = shift;
23              
24 0           return ($self->columns_to)[0]->table;
25             }
26              
27             sub columns_from
28             {
29 0     0 1   my $self = shift;
30              
31 0 0         return wantarray ? @{ $self->{columns_from} } : $self->{columns_from}[0];
  0            
32             }
33              
34             sub columns_to
35             {
36 0     0 1   my $self = shift;
37              
38 0 0         return wantarray ? @{ $self->{columns_to} } : $self->{columns_to}[0];
  0            
39             }
40              
41             sub column_pairs
42             {
43 0     0 1   my $self = shift;
44              
45 0           return ( map { [ $self->{columns_from}[$_] => $self->{columns_to}[$_] ] }
  0            
46 0           0..$#{ $self->{columns_from} } );
47             }
48              
49             sub column_pair_names
50             {
51 0     0 0   my $self = shift;
52              
53 0           return ( map { [ $self->{columns_from}[$_]->name => $self->{columns_to}[$_]->name ] }
  0            
54 0           0..$#{ $self->{columns_from} } );
55             }
56              
57             sub cardinality
58             {
59 0     0 1   my $self = shift;
60              
61 0           return @{ $self->{cardinality} };
  0            
62             }
63              
64             sub is_one_to_one
65             {
66 0     0 1   my $self = shift;
67              
68 0           my @c = $self->cardinality;
69              
70 0   0       return $c[0] eq '1' && $c[1] eq '1';
71             }
72              
73             sub is_one_to_many
74             {
75 0     0 1   my $self = shift;
76              
77 0           my @c = $self->cardinality;
78              
79 0   0       return $c[0] eq '1' && $c[1] eq 'n';
80             }
81              
82             sub is_many_to_one
83             {
84 0     0 1   my $self = shift;
85              
86 0           my @c = $self->cardinality;
87              
88 0   0       return $c[0] eq 'n' && $c[1] eq '1';
89             }
90              
91             sub from_is_dependent
92             {
93 0     0 1   return shift->{from_is_dependent};
94             }
95              
96             sub to_is_dependent
97             {
98 0     0 1   return shift->{to_is_dependent};
99             }
100              
101             sub is_same_relationship_as
102             {
103 0     0 1   my ($self, $other) = @_;
104 0   0       return ( $self->id eq $other->id
105             or
106             $self->id eq $other->reverse->id
107             );
108             }
109              
110             sub reverse
111             {
112 0     0 0   my $self = shift;
113              
114 0           return bless { table_from => $self->table_to,
115             table_to => $self->table_from,
116             columns_from => [ $self->columns_to ],
117             columns_to => [ $self->columns_from ],
118             from_is_dependent => $self->to_is_dependent,
119             to_is_dependent => $self->from_is_dependent,
120 0           cardinality => [ reverse @{ $self->{cardinality} } ],
121             }, ref $self;
122             }
123              
124             sub id
125             {
126 0     0 1   my $self = shift;
127              
128 0           return join '___', ( ( map { $_->name }
  0            
129             $self->table_from,
130             $self->table_to,
131             $self->columns_from,
132             $self->columns_to,
133             ),
134             $self->cardinality,
135             $self->from_is_dependent,
136             $self->to_is_dependent,
137             );
138             }
139              
140 0     0 1   sub comment { $_[0]->{comment} }
141              
142             __END__