line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Schema::Table; |
2
|
29
|
|
|
29
|
|
454
|
use 5.014002; |
|
29
|
|
|
|
|
96
|
|
3
|
|
|
|
|
|
|
|
4
|
29
|
|
|
29
|
|
148
|
use namespace::autoclean; |
|
29
|
|
|
|
|
59
|
|
|
29
|
|
|
|
|
192
|
|
5
|
29
|
|
|
29
|
|
1964
|
use Mouse v2.4.5; |
|
29
|
|
|
|
|
391
|
|
|
29
|
|
|
|
|
185
|
|
6
|
29
|
|
|
29
|
|
10048
|
use Carp qw/croak/; |
|
29
|
|
|
|
|
64
|
|
|
29
|
|
|
|
|
1215
|
|
7
|
29
|
|
|
29
|
|
9707
|
use Aniki::Schema::Relationships; |
|
29
|
|
|
|
|
2476
|
|
|
29
|
|
|
|
|
958
|
|
8
|
29
|
|
|
29
|
|
11896
|
use Aniki::Schema::Table::Field; |
|
29
|
|
|
|
|
2164
|
|
|
29
|
|
|
|
|
929
|
|
9
|
29
|
|
|
29
|
|
10460
|
use Aniki::Schema::Table::PrimaryKey; |
|
29
|
|
|
|
|
2159
|
|
|
29
|
|
|
|
|
982
|
|
10
|
29
|
|
|
29
|
|
239
|
use SQL::Translator::Schema::Constants; |
|
29
|
|
|
|
|
59
|
|
|
29
|
|
|
|
|
22005
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has _schema => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
weak_ref => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has _table => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
required => 1, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has name => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
default => sub { shift->_table->name }, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has relationships => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
default => \&_setup_relationships, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has primary_key => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
default => sub { |
36
|
|
|
|
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
if (my $primary_key = $self->_table->primary_key) { |
38
|
|
|
|
|
|
|
return Aniki::Schema::Table::PrimaryKey->new($primary_key); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
return undef; |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has _fields_cache => ( |
45
|
|
|
|
|
|
|
is => 'ro', |
46
|
|
|
|
|
|
|
default => sub { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
return [ |
49
|
|
|
|
|
|
|
map { Aniki::Schema::Table::Field->new($_) } $self->_table->get_fields |
50
|
|
|
|
|
|
|
] |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has _field_names => ( |
55
|
|
|
|
|
|
|
is => 'ro', |
56
|
|
|
|
|
|
|
default => sub { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
return [map { $_->name } @{ $self->_fields_cache }]; |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has _fields_map_cache => ( |
63
|
|
|
|
|
|
|
is => 'ro', |
64
|
|
|
|
|
|
|
default => sub { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
return { |
67
|
|
|
|
|
|
|
map { $_->name => $_ } @{ $self->_fields_cache } |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub BUILDARGS { |
73
|
89
|
|
|
89
|
1
|
11967
|
my ($class, $table, $schema) = @_; |
74
|
89
|
|
|
|
|
1036
|
return $class->SUPER::BUILDARGS(_table => $table, _schema => $schema); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
8
|
|
|
8
|
0
|
13
|
sub get_fields { @{ shift->_fields_cache } } |
|
8
|
|
|
|
|
36
|
|
78
|
|
|
|
|
|
|
|
79
|
83
|
100
|
|
83
|
0
|
202
|
sub field_names { wantarray ? @{ shift->_field_names } : [@{ shift->_field_names }] } |
|
4
|
|
|
|
|
25
|
|
|
79
|
|
|
|
|
370
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_field { |
82
|
132
|
|
|
132
|
0
|
275
|
my ($self, $name) = @_; |
83
|
132
|
50
|
|
|
|
476
|
return unless exists $self->_fields_map_cache->{$name}; |
84
|
132
|
|
|
|
|
512
|
return $self->_fields_map_cache->{$name} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
251
|
|
|
251
|
0
|
921
|
sub get_relationships { shift->relationships } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _setup_relationships { |
90
|
89
|
|
|
89
|
|
8956
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
89
|
|
|
|
|
725
|
my @constraints = grep { $_->type eq FOREIGN_KEY } $self->get_constraints; |
|
94
|
|
|
|
|
4534
|
|
93
|
89
|
|
|
|
|
9795
|
for my $table ($self->_schema->context->schema->get_tables) { |
94
|
265
|
|
|
|
|
29233
|
for my $constraint ($table->get_constraints) { |
95
|
279
|
100
|
|
|
|
11437
|
next if $constraint->type ne FOREIGN_KEY; |
96
|
9
|
100
|
|
|
|
773
|
next if $constraint->reference_table ne $self->name; |
97
|
3
|
|
|
|
|
7
|
push @constraints => $constraint; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
89
|
|
|
|
|
8629
|
my $relationships = Aniki::Schema::Relationships->new(schema => $self->_schema, table => $self); |
102
|
89
|
|
|
|
|
287
|
for my $constraint (@constraints) { |
103
|
6
|
|
|
|
|
23
|
$relationships->add_by_constraint($constraint); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
89
|
100
|
|
|
|
1035
|
if ($self->_schema->schema_class->can('relationship_rules')) { |
107
|
86
|
|
|
|
|
436
|
my $rules = $self->_schema->schema_class->relationship_rules; |
108
|
86
|
|
|
|
|
246
|
for my $rule (@$rules) { |
109
|
336
|
100
|
|
|
|
23867
|
next if $rule->{src_table_name} ne $self->_table->name; |
110
|
112
|
|
|
|
|
11528
|
$relationships->add(%$rule); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
89
|
|
|
|
|
6254
|
return $relationships; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
our $AUTOLOAD; |
118
|
|
|
|
|
|
|
sub AUTOLOAD { |
119
|
90
|
|
|
90
|
|
212
|
my $self = shift; |
120
|
90
|
|
|
|
|
497
|
my $method = $AUTOLOAD =~ s/^.*://r; |
121
|
90
|
50
|
|
|
|
632
|
if ($self->_table->can($method)) { |
122
|
90
|
|
|
|
|
429
|
return $self->_table->$method(@_); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $class = ref $self; |
126
|
0
|
|
|
|
|
|
croak qq{Can't locate object method "$method" via package "$class"}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
130
|
|
|
|
|
|
|
__END__ |