line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Schema::Relationships; |
2
|
29
|
|
|
29
|
|
502
|
use 5.014002; |
|
29
|
|
|
|
|
112
|
|
3
|
|
|
|
|
|
|
|
4
|
29
|
|
|
29
|
|
186
|
use namespace::autoclean; |
|
29
|
|
|
|
|
64
|
|
|
29
|
|
|
|
|
181
|
|
5
|
29
|
|
|
29
|
|
2042
|
use Mouse v2.4.5; |
|
29
|
|
|
|
|
454
|
|
|
29
|
|
|
|
|
182
|
|
6
|
29
|
|
|
29
|
|
10188
|
use SQL::Translator::Schema::Constants; |
|
29
|
|
|
|
|
88
|
|
|
29
|
|
|
|
|
1867
|
|
7
|
29
|
|
|
29
|
|
11129
|
use Aniki::Schema::Relationship; |
|
29
|
|
|
|
|
3514
|
|
|
29
|
|
|
|
|
16528
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has schema => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
required => 1, |
12
|
|
|
|
|
|
|
weak_ref => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has table => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has rule => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
default => sub { +{} }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub add { |
26
|
121
|
|
|
121
|
0
|
2983
|
my $self = shift; |
27
|
121
|
|
|
|
|
19385
|
my $relationship = Aniki::Schema::Relationship->new(schema => $self->schema, @_); |
28
|
|
|
|
|
|
|
|
29
|
121
|
|
|
|
|
2504
|
my $name = $relationship->name; |
30
|
121
|
50
|
|
|
|
660
|
exists $self->rule->{$name} |
31
|
0
|
|
|
|
|
0
|
and die "already exists $name in rule. (table:@{[ $self->table->name ]})"; |
32
|
121
|
|
|
|
|
754
|
$self->rule->{$name} = $relationship; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_by_constraint { |
36
|
7
|
|
|
7
|
0
|
253
|
my ($self, $constraint) = @_; |
37
|
7
|
50
|
|
|
|
129
|
die "Invalid constraint: @{[ $constraint->name ]}. (table:@{[ $self->table->name ]})" if $constraint->type ne FOREIGN_KEY; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
|
|
|
747
|
if ($constraint->table->name eq $self->table->name) { |
|
|
50
|
|
|
|
|
|
40
|
4
|
|
|
|
|
761
|
$self->add( |
41
|
|
|
|
|
|
|
src_table_name => $constraint->table->name, |
42
|
|
|
|
|
|
|
src_columns => [$constraint->field_names], |
43
|
|
|
|
|
|
|
dest_table_name => $constraint->reference_table, |
44
|
|
|
|
|
|
|
dest_columns => [$constraint->reference_fields], |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($constraint->reference_table eq $self->table->name) { |
48
|
3
|
|
|
|
|
692
|
$self->add( |
49
|
|
|
|
|
|
|
src_table_name => $constraint->reference_table, |
50
|
|
|
|
|
|
|
src_columns => [$constraint->reference_fields], |
51
|
|
|
|
|
|
|
dest_table_name => $constraint->table->name, |
52
|
|
|
|
|
|
|
dest_columns => [$constraint->field_names], |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
0
|
die "Invalid constraint: @{[ $constraint->name ]}. (table:@{[ $self->table->name ]})"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub names { |
61
|
210
|
|
|
210
|
0
|
361
|
my $self = shift; |
62
|
210
|
|
|
|
|
342
|
return keys %{ $self->rule }; |
|
210
|
|
|
|
|
813
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub all { |
66
|
207
|
|
|
207
|
0
|
380
|
my $self = shift; |
67
|
207
|
|
|
|
|
486
|
return map { $self->get($_) } $self->names; |
|
298
|
|
|
|
|
701
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get { |
71
|
337
|
|
|
337
|
0
|
698
|
my ($self, $name) = @_; |
72
|
337
|
100
|
|
|
|
1204
|
return unless exists $self->rule->{$name}; |
73
|
333
|
|
|
|
|
1171
|
return $self->rule->{$name}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
77
|
|
|
|
|
|
|
__END__ |