line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Schema; |
2
|
29
|
|
|
29
|
|
112079
|
use 5.014002; |
|
29
|
|
|
|
|
97
|
|
3
|
|
|
|
|
|
|
|
4
|
29
|
|
|
29
|
|
1039
|
use namespace::autoclean; |
|
29
|
|
|
|
|
29528
|
|
|
29
|
|
|
|
|
162
|
|
5
|
29
|
|
|
29
|
|
2616
|
use Mouse v2.4.5; |
|
29
|
|
|
|
|
41551
|
|
|
29
|
|
|
|
|
168
|
|
6
|
|
|
|
|
|
|
|
7
|
29
|
|
|
29
|
|
21777
|
use SQL::Translator::Schema::Constants; |
|
29
|
|
|
|
|
17014
|
|
|
29
|
|
|
|
|
1906
|
|
8
|
29
|
|
|
29
|
|
194
|
use Carp qw/croak/; |
|
29
|
|
|
|
|
57
|
|
|
29
|
|
|
|
|
1149
|
|
9
|
29
|
|
|
29
|
|
9404
|
use Aniki::Schema::Table; |
|
29
|
|
|
|
|
2379
|
|
|
29
|
|
|
|
|
16711
|
|
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
|
89
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# for cache |
35
|
30
|
|
|
|
|
133
|
for my $table ($self->get_tables) { |
36
|
89
|
|
|
|
|
339
|
for my $relationship ($table->get_relationships->all) { |
37
|
118
|
|
|
|
|
402
|
$relationship->get_inverse_relationships(); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_table { |
43
|
371
|
|
|
371
|
0
|
5276
|
my ($self, $table_name) = @_; |
44
|
371
|
50
|
|
|
|
1430
|
return unless exists $self->_table_cache->{$table_name}; |
45
|
371
|
|
|
|
|
1326
|
return $self->_table_cache->{$table_name}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_tables { |
49
|
78
|
|
|
78
|
0
|
169
|
my $self = shift; |
50
|
78
|
|
|
|
|
146
|
return values %{ $self->_table_cache }; |
|
78
|
|
|
|
|
411
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub has_many { |
54
|
72
|
|
|
72
|
0
|
213
|
my ($self, $table_name, $fields) = @_; |
55
|
72
|
|
|
|
|
1525
|
my $table = $self->context->schema->get_table($table_name); |
56
|
72
|
50
|
|
|
|
1675
|
return !!1 unless defined $table; |
57
|
|
|
|
|
|
|
|
58
|
72
|
|
|
|
|
207
|
my %field = map { $_ => 1 } @$fields; |
|
72
|
|
|
|
|
351
|
|
59
|
72
|
100
|
|
|
|
334
|
for my $unique (grep { $_->type eq UNIQUE || $_->type eq PRIMARY_KEY } $table->get_constraints) { |
|
86
|
|
|
|
|
5852
|
|
60
|
77
|
|
|
|
|
15726
|
my @field_names = $unique->field_names; |
61
|
77
|
|
|
|
|
5087
|
my @related_fields = grep { $field{$_} } @field_names; |
|
77
|
|
|
|
|
293
|
|
62
|
77
|
100
|
|
|
|
829
|
return !!0 if @field_names == @related_fields; |
63
|
|
|
|
|
|
|
} |
64
|
9
|
|
|
|
|
40
|
for my $index (grep { $_->type eq UNIQUE } $table->get_indices) { |
|
12
|
|
|
|
|
739
|
|
65
|
2
|
|
|
|
|
242
|
my @field_names = $index->fields; |
66
|
2
|
|
|
|
|
123
|
my @related_fields = grep { $field{$_} } @field_names; |
|
2
|
|
|
|
|
8
|
|
67
|
2
|
100
|
|
|
|
17
|
return !!0 if @field_names == @related_fields; |
68
|
|
|
|
|
|
|
} |
69
|
8
|
|
|
|
|
717
|
return !!1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
our $AUTOLOAD; |
73
|
|
|
|
|
|
|
sub AUTOLOAD { |
74
|
65
|
|
|
65
|
|
153
|
my $self = shift; |
75
|
65
|
|
|
|
|
444
|
my $method = $AUTOLOAD =~ s/^.*://r; |
76
|
65
|
50
|
|
|
|
1585
|
if ($self->context->schema->can($method)) { |
77
|
65
|
|
|
|
|
1741
|
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__ |