line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Schema::Table; |
2
|
29
|
|
|
29
|
|
646
|
use 5.014002; |
|
29
|
|
|
|
|
113
|
|
3
|
|
|
|
|
|
|
|
4
|
29
|
|
|
29
|
|
171
|
use namespace::autoclean; |
|
29
|
|
|
|
|
64
|
|
|
29
|
|
|
|
|
193
|
|
5
|
29
|
|
|
29
|
|
2267
|
use Mouse v2.4.5; |
|
29
|
|
|
|
|
401
|
|
|
29
|
|
|
|
|
220
|
|
6
|
29
|
|
|
29
|
|
10890
|
use Carp qw/croak/; |
|
29
|
|
|
|
|
75
|
|
|
29
|
|
|
|
|
1419
|
|
7
|
29
|
|
|
29
|
|
11177
|
use Aniki::Schema::Relationships; |
|
29
|
|
|
|
|
3016
|
|
|
29
|
|
|
|
|
1130
|
|
8
|
29
|
|
|
29
|
|
14535
|
use Aniki::Schema::Table::Field; |
|
29
|
|
|
|
|
2619
|
|
|
29
|
|
|
|
|
1108
|
|
9
|
29
|
|
|
29
|
|
12380
|
use Aniki::Schema::Table::PrimaryKey; |
|
29
|
|
|
|
|
2365
|
|
|
29
|
|
|
|
|
1132
|
|
10
|
29
|
|
|
29
|
|
224
|
use SQL::Translator::Schema::Constants; |
|
29
|
|
|
|
|
63
|
|
|
29
|
|
|
|
|
23857
|
|
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
|
14552
|
my ($class, $table, $schema) = @_; |
74
|
89
|
|
|
|
|
1394
|
return $class->SUPER::BUILDARGS(_table => $table, _schema => $schema); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
8
|
|
|
8
|
0
|
17
|
sub get_fields { @{ shift->_fields_cache } } |
|
8
|
|
|
|
|
52
|
|
78
|
|
|
|
|
|
|
|
79
|
78
|
100
|
|
78
|
0
|
236
|
sub field_names { wantarray ? @{ shift->_field_names } : [@{ shift->_field_names }] } |
|
4
|
|
|
|
|
34
|
|
|
74
|
|
|
|
|
474
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_field { |
82
|
131
|
|
|
131
|
0
|
317
|
my ($self, $name) = @_; |
83
|
131
|
50
|
|
|
|
584
|
return unless exists $self->_fields_map_cache->{$name}; |
84
|
131
|
|
|
|
|
639
|
return $self->_fields_map_cache->{$name} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
248
|
|
|
248
|
0
|
1036
|
sub get_relationships { shift->relationships } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _setup_relationships { |
90
|
89
|
|
|
89
|
|
10584
|
my $self = shift; |
91
|
|
|
|
|
|
|
|
92
|
89
|
|
|
|
|
950
|
my @constraints = grep { $_->type eq FOREIGN_KEY } $self->get_constraints; |
|
94
|
|
|
|
|
6838
|
|
93
|
89
|
|
|
|
|
12102
|
for my $table ($self->_schema->context->schema->get_tables) { |
94
|
265
|
|
|
|
|
35631
|
for my $constraint ($table->get_constraints) { |
95
|
279
|
100
|
|
|
|
14164
|
next if $constraint->type ne FOREIGN_KEY; |
96
|
9
|
100
|
|
|
|
748
|
next if $constraint->reference_table ne $self->name; |
97
|
3
|
|
|
|
|
8
|
push @constraints => $constraint; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
89
|
|
|
|
|
11817
|
my $relationships = Aniki::Schema::Relationships->new(schema => $self->_schema, table => $self); |
102
|
89
|
|
|
|
|
440
|
for my $constraint (@constraints) { |
103
|
6
|
|
|
|
|
20
|
$relationships->add_by_constraint($constraint); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
89
|
100
|
|
|
|
1465
|
if ($self->_schema->schema_class->can('relationship_rules')) { |
107
|
86
|
|
|
|
|
615
|
my $rules = $self->_schema->schema_class->relationship_rules; |
108
|
86
|
|
|
|
|
325
|
for my $rule (@$rules) { |
109
|
336
|
100
|
|
|
|
27888
|
next if $rule->{src_table_name} ne $self->_table->name; |
110
|
112
|
|
|
|
|
14909
|
$relationships->add(%$rule); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
89
|
|
|
|
|
8190
|
return $relationships; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
our $AUTOLOAD; |
118
|
|
|
|
|
|
|
sub AUTOLOAD { |
119
|
90
|
|
|
90
|
|
255
|
my $self = shift; |
120
|
90
|
|
|
|
|
638
|
my $method = $AUTOLOAD =~ s/^.*://r; |
121
|
90
|
50
|
|
|
|
858
|
if ($self->_table->can($method)) { |
122
|
90
|
|
|
|
|
541
|
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__ |