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