line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Schema; |
2
|
29
|
|
|
29
|
|
102387
|
use 5.014002; |
|
29
|
|
|
|
|
122
|
|
3
|
|
|
|
|
|
|
|
4
|
29
|
|
|
29
|
|
870
|
use namespace::autoclean; |
|
29
|
|
|
|
|
28652
|
|
|
29
|
|
|
|
|
187
|
|
5
|
29
|
|
|
29
|
|
2981
|
use Mouse v2.4.5; |
|
29
|
|
|
|
|
41145
|
|
|
29
|
|
|
|
|
194
|
|
6
|
|
|
|
|
|
|
|
7
|
29
|
|
|
29
|
|
24125
|
use SQL::Translator::Schema::Constants; |
|
29
|
|
|
|
|
18256
|
|
|
29
|
|
|
|
|
2184
|
|
8
|
29
|
|
|
29
|
|
204
|
use Carp qw/croak/; |
|
29
|
|
|
|
|
66
|
|
|
29
|
|
|
|
|
1251
|
|
9
|
29
|
|
|
29
|
|
11091
|
use Aniki::Schema::Table; |
|
29
|
|
|
|
|
2652
|
|
|
29
|
|
|
|
|
19148
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has schema_class => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has context => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
default => sub { shift->schema_class->context } |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _table_cache => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
default => sub { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
return { |
26
|
|
|
|
|
|
|
map { $_->name => Aniki::Schema::Table->new($_, $self) } $self->context->schema->get_tables() |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub BUILD { |
32
|
30
|
|
|
30
|
1
|
121
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# for cache |
35
|
30
|
|
|
|
|
170
|
for my $table ($self->get_tables) { |
36
|
89
|
|
|
|
|
344
|
for my $relationship ($table->get_relationships->all) { |
37
|
118
|
|
|
|
|
414
|
$relationship->get_inverse_relationships(); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_table { |
43
|
362
|
|
|
362
|
0
|
4551
|
my ($self, $table_name) = @_; |
44
|
362
|
50
|
|
|
|
1523
|
return unless exists $self->_table_cache->{$table_name}; |
45
|
362
|
|
|
|
|
1547
|
return $self->_table_cache->{$table_name}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_tables { |
49
|
78
|
|
|
78
|
0
|
194
|
my $self = shift; |
50
|
78
|
|
|
|
|
173
|
return values %{ $self->_table_cache }; |
|
78
|
|
|
|
|
488
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub has_many { |
54
|
72
|
|
|
72
|
0
|
392
|
my ($self, $table_name, $fields) = @_; |
55
|
72
|
|
|
|
|
1733
|
my $table = $self->context->schema->get_table($table_name); |
56
|
72
|
50
|
|
|
|
2078
|
return !!1 unless defined $table; |
57
|
|
|
|
|
|
|
|
58
|
72
|
|
|
|
|
227
|
my %field = map { $_ => 1 } @$fields; |
|
72
|
|
|
|
|
396
|
|
59
|
72
|
100
|
|
|
|
333
|
for my $unique (grep { $_->type eq UNIQUE || $_->type eq PRIMARY_KEY } $table->get_constraints) { |
|
86
|
|
|
|
|
5685
|
|
60
|
77
|
|
|
|
|
16782
|
my @field_names = $unique->field_names; |
61
|
77
|
|
|
|
|
7145
|
my @related_fields = grep { $field{$_} } @field_names; |
|
77
|
|
|
|
|
294
|
|
62
|
77
|
100
|
|
|
|
993
|
return !!0 if @field_names == @related_fields; |
63
|
|
|
|
|
|
|
} |
64
|
9
|
|
|
|
|
37
|
for my $index (grep { $_->type eq UNIQUE } $table->get_indices) { |
|
12
|
|
|
|
|
688
|
|
65
|
2
|
|
|
|
|
204
|
my @field_names = $index->fields; |
66
|
2
|
|
|
|
|
112
|
my @related_fields = grep { $field{$_} } @field_names; |
|
2
|
|
|
|
|
6
|
|
67
|
2
|
100
|
|
|
|
12
|
return !!0 if @field_names == @related_fields; |
68
|
|
|
|
|
|
|
} |
69
|
8
|
|
|
|
|
702
|
return !!1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
our $AUTOLOAD; |
73
|
|
|
|
|
|
|
sub AUTOLOAD { |
74
|
65
|
|
|
65
|
|
170
|
my $self = shift; |
75
|
65
|
|
|
|
|
537
|
my $method = $AUTOLOAD =~ s/^.*://r; |
76
|
65
|
50
|
|
|
|
1857
|
if ($self->context->schema->can($method)) { |
77
|
65
|
|
|
|
|
2047
|
return $self->context->schema->$method(@_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $class = ref $self; |
81
|
0
|
|
|
|
|
|
croak qq{Can't locate object method "$method" via package "$class"}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
85
|
|
|
|
|
|
|
__END__ |