line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alzabo::Create::ForeignKey; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
50
|
use strict; |
|
9
|
|
|
|
|
40
|
|
|
9
|
|
|
|
|
918
|
|
4
|
9
|
|
|
9
|
|
54
|
use vars qw($VERSION); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
406
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
64
|
use Alzabo::Create; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
266
|
|
7
|
9
|
|
|
9
|
|
69
|
use Alzabo::Exceptions ( abbr => 'params_exception' ); |
|
9
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
191
|
|
8
|
9
|
|
|
9
|
|
51
|
use Alzabo::Utils; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
384
|
|
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
47
|
use Params::Validate qw( :all ); |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
2278
|
|
11
|
|
|
|
|
|
|
Params::Validate::validation_options |
12
|
|
|
|
|
|
|
( on_fail => sub { params_exception join '', @_ } ); |
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
57
|
use base qw(Alzabo::ForeignKey); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
9251
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = 2.0; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
23
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
validate( @_, { columns_from => { type => ARRAYREF | OBJECT }, |
26
|
|
|
|
|
|
|
columns_to => { type => ARRAYREF | OBJECT }, |
27
|
|
|
|
|
|
|
cardinality => { type => ARRAYREF }, |
28
|
|
|
|
|
|
|
from_is_dependent => { type => SCALAR }, |
29
|
|
|
|
|
|
|
to_is_dependent => { type => SCALAR }, |
30
|
|
|
|
|
|
|
comment => { type => UNDEF | SCALAR, |
31
|
|
|
|
|
|
|
default => '' }, |
32
|
|
|
|
|
|
|
} ); |
33
|
0
|
|
|
|
|
|
my %p = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->set_columns_from( $p{columns_from} ); |
38
|
0
|
|
|
|
|
|
$self->set_columns_to( $p{columns_to} ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->set_cardinality( @{ $p{cardinality} } ); |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->set_from_is_dependent( $p{from_is_dependent} ); |
42
|
0
|
|
|
|
|
|
$self->set_to_is_dependent( $p{to_is_dependent} ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->set_comment( $p{comment} ); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub set_columns_from |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
my $c = Alzabo::Utils::is_arrayref( $_[0] ) ? shift : [ shift ]; |
54
|
0
|
|
|
|
|
|
validate_pos( @$c, ( { isa => 'Alzabo::Create::Column' } ) x @$c ); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( exists $self->{columns_to} ) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
|
params_exception |
59
|
|
|
|
|
|
|
"The number of columns in each part of the relationship must be the same" |
60
|
0
|
0
|
|
|
|
|
unless @{ $self->{columns_to} } == @$c; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->{columns_from} = $c; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set_columns_to |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
my $c = Alzabo::Utils::is_arrayref( $_[0] ) ? shift : [ shift ]; |
71
|
0
|
|
|
|
|
|
validate_pos( @$c, ( { isa => 'Alzabo::Create::Column' } ) x @$c ); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( exists $self->{columns_from} ) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
|
params_exception |
76
|
|
|
|
|
|
|
"The number of columns in each part of the relationship must be the same" |
77
|
0
|
0
|
|
|
|
|
unless @{ $self->{columns_from} } == @$c; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->{columns_to} = $c; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub set_cardinality |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my @card = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
params_exception "Incorrect number of elements for cardinality" |
90
|
|
|
|
|
|
|
unless scalar @card == 2; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
foreach my $c ( @card ) |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
0
|
|
|
|
|
params_exception "Invalid cardinality piece: $c" |
95
|
|
|
|
|
|
|
unless $c =~ /^[1n]$/i; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
0
|
|
|
|
params_exception "Invalid cardinality: $card[0]..$card[1]" |
99
|
|
|
|
|
|
|
if $card[0] eq 'n' && $card[1] eq 'n'; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->{cardinality} = \@card; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub set_from_is_dependent |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->{from_is_dependent} = shift; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub set_to_is_dependent |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$self->{to_is_dependent} = shift; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
0
|
1
|
|
sub set_comment { $_[0]->{comment} = defined $_[1] ? $_[1] : '' } |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |