line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Lite::Schema::Table; |
2
|
|
|
|
|
|
|
$DBIx::Lite::Schema::Table::VERSION = '0.32'; |
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
17
|
use Carp qw(croak); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1293
|
|
7
|
|
|
|
|
|
|
$Carp::Internal{$_}++ for __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
4
|
|
|
4
|
1
|
9
|
my $class = shift; |
11
|
4
|
|
|
|
|
17
|
my (%params) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $self = { |
14
|
|
|
|
|
|
|
class => undef, |
15
|
|
|
|
|
|
|
resultset_class => undef, |
16
|
4
|
|
50
|
|
|
43
|
pk => delete $params{pk} || [], |
17
|
|
|
|
|
|
|
has_many => {}, |
18
|
|
|
|
|
|
|
has_one => {}, |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
15
|
for (qw(name)) { |
22
|
4
|
50
|
|
|
|
21
|
$self->{$_} = delete $params{$_} or croak "$_ argument needed"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
4
|
50
|
|
|
|
17
|
if ($self->{autopk} = delete $params{autopk}) { |
26
|
0
|
0
|
|
|
|
0
|
!ref $self->{autopk} or croak "autopk only accepts a single column"; |
27
|
0
|
|
|
|
|
0
|
$self->{pk} = [$self->{autopk}]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
50
|
|
|
|
14
|
!%params |
31
|
|
|
|
|
|
|
or croak "Unknown options: " . join(', ', keys %params); |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
10
|
bless $self, $class; |
34
|
4
|
|
|
|
|
28
|
$self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub pk { |
38
|
4
|
|
|
4
|
1
|
10
|
my $self = shift; |
39
|
4
|
|
|
|
|
12
|
my @cols = @_; |
40
|
|
|
|
|
|
|
|
41
|
4
|
100
|
|
|
|
11
|
if (@cols) { |
42
|
|
|
|
|
|
|
$self->{pk} = [ |
43
|
|
|
|
|
|
|
grep defined $_, |
44
|
3
|
50
|
|
|
|
8
|
map { (ref $_ eq 'ARRAY') ? @$_ : $_ } @cols |
|
3
|
|
|
|
|
23
|
|
45
|
|
|
|
|
|
|
]; |
46
|
3
|
|
|
|
|
8
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
2
|
return @{$self->{pk}}; |
|
1
|
|
|
|
|
7
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub autopk { |
52
|
5
|
|
|
5
|
1
|
13
|
my $self = shift; |
53
|
5
|
|
|
|
|
9
|
my $val = shift; |
54
|
|
|
|
|
|
|
|
55
|
5
|
50
|
|
|
|
16
|
if ($val) { |
56
|
0
|
|
|
|
|
0
|
$self->{autopk} = $val; |
57
|
0
|
|
|
|
|
0
|
$self->{pk} = [$val]; |
58
|
0
|
|
|
|
|
0
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
5
|
|
|
|
|
21
|
return $self->{autopk}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub class { |
64
|
1
|
|
|
1
|
1
|
3
|
my ($self, $class, $constructor, $storage) = @_; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
$self->{class} = $class; |
67
|
1
|
|
|
|
|
3
|
$self->{class_constructor} = $constructor; |
68
|
1
|
|
|
|
|
2
|
$self->{class_storage} = $storage; |
69
|
|
|
|
|
|
|
|
70
|
1
|
50
|
|
|
|
13
|
return undef if !$class; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# make the custom class inherit from our base |
73
|
1
|
50
|
|
|
|
17
|
if (!$class->isa('DBIx::Lite::Row')) { |
74
|
3
|
|
|
3
|
|
24
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
201
|
|
75
|
1
|
|
|
|
|
2
|
push @{"${class}::ISA"}, 'DBIx::Lite::Row'; |
|
1
|
|
|
|
|
16
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# install the storage provider |
79
|
1
|
50
|
|
|
|
5
|
if ($storage) { |
80
|
3
|
|
|
3
|
|
20
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
87
|
|
81
|
3
|
|
|
3
|
|
15
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
582
|
|
82
|
1
|
|
|
|
|
15
|
*{ "${class}::__dbix_lite_row_storage" } = sub { |
83
|
1
|
|
|
1
|
|
3
|
my ($row) = @_; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
5
|
croak "$class does not provide a $storage method" |
86
|
|
|
|
|
|
|
if !$row->can($storage); |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
4
|
return $row->$storage; |
89
|
1
|
|
|
|
|
6
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
4
|
return $class; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub resultset_class { |
96
|
25
|
|
|
25
|
1
|
69
|
my $self = shift; |
97
|
25
|
|
|
|
|
67
|
my $class = shift; |
98
|
|
|
|
|
|
|
|
99
|
25
|
100
|
|
|
|
58
|
if ($class) { |
100
|
1
|
|
|
|
|
3
|
$self->{resultset_class} = $class; |
101
|
1
|
|
|
|
|
3
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
24
|
|
|
|
|
62
|
$class = $self->{resultset_class}; |
105
|
24
|
100
|
|
|
|
136
|
return undef if !$class; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# make the custom class inherit from our base |
108
|
1
|
50
|
|
|
|
16
|
if (!$class->isa('DBIx::Lite::ResultSet')) { |
109
|
3
|
|
|
3
|
|
22
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
255
|
|
110
|
1
|
|
|
|
|
3
|
push @{"${class}::ISA"}, 'DBIx::Lite::ResultSet'; |
|
1
|
|
|
|
|
12
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
6
|
return $class; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |