| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Lite::Schema; |
|
2
|
|
|
|
|
|
|
$DBIx::Lite::Schema::VERSION = '0.33'; |
|
3
|
3
|
|
|
3
|
|
23
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
90
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
85
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use Carp qw(croak); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
141
|
|
|
7
|
3
|
|
|
3
|
|
1461
|
use DBIx::Lite::Schema::Table; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
1318
|
|
|
8
|
|
|
|
|
|
|
$Carp::Internal{$_}++ for __PACKAGE__; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
3
|
|
|
3
|
1
|
7
|
my $class = shift; |
|
12
|
3
|
|
|
|
|
10
|
my (%params) = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
11
|
my $self = { |
|
15
|
|
|
|
|
|
|
tables => {}, |
|
16
|
|
|
|
|
|
|
}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
3
|
50
|
|
|
|
13
|
if (my $tables = delete $params{tables}) { |
|
19
|
0
|
|
|
|
|
0
|
foreach my $table_name (keys %$tables) { |
|
20
|
0
|
|
|
|
|
0
|
$tables->{$table_name}{name} = $table_name; |
|
21
|
0
|
|
|
|
|
0
|
$self->{tables}{$table_name} = DBIx::Lite::Schema::Table->new($tables->{$table_name}); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
50
|
|
|
|
10
|
!%params |
|
26
|
|
|
|
|
|
|
or croak "Unknown options: " . join(', ', keys %params); |
|
27
|
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
9
|
bless $self, $class; |
|
29
|
3
|
|
|
|
|
25
|
$self; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub table { |
|
33
|
33
|
|
|
33
|
1
|
77
|
my $self = shift; |
|
34
|
33
|
|
|
|
|
75
|
my $table_name = shift; |
|
35
|
33
|
|
66
|
|
|
171
|
$self->{tables}{$table_name} ||= DBIx::Lite::Schema::Table->new(name => $table_name); |
|
36
|
33
|
|
|
|
|
115
|
return $self->{tables}{$table_name}; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub one_to_many { |
|
40
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
|
41
|
2
|
|
|
|
|
10
|
my ($from, $to, $accessors) = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
2
|
50
|
33
|
|
|
27
|
$from && $from =~ /^(.+)\.(.+)$/ |
|
44
|
|
|
|
|
|
|
or croak "Relationship keys must be defined in table.column format"; |
|
45
|
2
|
|
|
|
|
11
|
my $from_table = $self->table($1); |
|
46
|
2
|
|
|
|
|
7
|
my $from_key = $2; |
|
47
|
|
|
|
|
|
|
|
|
48
|
2
|
50
|
33
|
|
|
17
|
$to && $to =~ /^(.+)\.(.+)$/ |
|
49
|
|
|
|
|
|
|
or croak "Relationship keys must be defined in table.column format"; |
|
50
|
2
|
|
|
|
|
6
|
my $to_table = $self->table($1); |
|
51
|
2
|
|
|
|
|
5
|
my $to_key = $2; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
6
|
my $from_table_accessor = $to_table->{name}; |
|
54
|
2
|
|
|
|
|
4
|
my $to_table_accessor; |
|
55
|
2
|
50
|
|
|
|
6
|
if ($accessors) { |
|
56
|
2
|
100
|
|
|
|
9
|
if (ref $accessors eq 'ARRAY') { |
|
57
|
1
|
|
|
|
|
3
|
($from_table_accessor, $to_table_accessor) = @$accessors; |
|
58
|
|
|
|
|
|
|
} else { |
|
59
|
1
|
|
|
|
|
3
|
$to_table_accessor = $accessors; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
56
|
$from_table->{has_many}{ $from_table_accessor } = [ $to_table->{name}, { $from_key => $to_key } ]; |
|
64
|
2
|
50
|
|
|
|
19
|
$to_table->{has_one}{ $to_table_accessor } = [ $from_table->{name}, { $to_key => $from_key } ] |
|
65
|
|
|
|
|
|
|
if $to_table_accessor; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |