line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE |
2
|
|
|
|
|
|
|
DBIx::Class::CDBICompat::LazyLoading; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1351
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1538
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub resultset_instance { |
8
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
9
|
0
|
|
|
|
|
|
my $rs = $self->next::method(@_); |
10
|
0
|
|
|
|
|
|
$rs = $rs->search(undef, { columns => [ $self->columns('Essential') ] }); |
11
|
0
|
|
|
|
|
|
return $rs; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Emulate that CDBI throws out all changed columns and reloads them on |
16
|
|
|
|
|
|
|
# request in case the database modifies the new value (say, via a trigger) |
17
|
|
|
|
|
|
|
sub update { |
18
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my @dirty_columns = keys %{$self->{_dirty_columns}}; |
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $ret = $self->next::method(@_); |
23
|
0
|
|
|
|
|
|
$self->_clear_column_data(@dirty_columns); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
return $ret; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# And again for create |
30
|
|
|
|
|
|
|
sub create { |
31
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
32
|
0
|
|
|
|
|
|
my($data) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @columns = keys %$data; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $obj = $class->next::method(@_); |
37
|
0
|
0
|
|
|
|
|
return $obj unless defined $obj; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my %primary_cols = map { $_ => 1 } $class->primary_columns; |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my @data_cols = grep !$primary_cols{$_}, @columns; |
41
|
0
|
|
|
|
|
|
$obj->_clear_column_data(@data_cols); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $obj; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _clear_column_data { |
48
|
0
|
|
|
0
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
delete $self->{_column_data}{$_} for @_; |
51
|
0
|
|
|
|
|
|
delete $self->{_inflated_column}{$_} for @_; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_column { |
56
|
0
|
|
|
0
|
0
|
|
my ($self, $col) = @_; |
57
|
0
|
0
|
0
|
|
|
|
if ((ref $self) && (!exists $self->{'_column_data'}{$col}) |
|
|
|
0
|
|
|
|
|
58
|
|
|
|
|
|
|
&& $self->{'_in_storage'}) { |
59
|
0
|
0
|
|
|
|
|
$self->_flesh(grep { exists $self->_column_groups->{$_}{$col} |
60
|
|
|
|
|
|
|
&& $_ ne 'All' } |
61
|
0
|
0
|
|
|
|
|
keys %{ $self->_column_groups || {} }); |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
$self->next::method(@_[1..$#_]); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# CDBI does not explicitly declare auto increment columns, so |
67
|
|
|
|
|
|
|
# we just clear out our primary columns before copying. |
68
|
|
|
|
|
|
|
sub copy { |
69
|
0
|
|
|
0
|
0
|
|
my($self, $changes) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
for my $col ($self->primary_columns) { |
72
|
0
|
0
|
|
|
|
|
$changes->{$col} = undef unless exists $changes->{$col}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->next::method($changes); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub discard_changes { |
79
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
delete $self->{_column_data}{$_} for $self->is_changed; |
82
|
0
|
|
|
|
|
|
delete $self->{_dirty_columns}; |
83
|
0
|
|
|
|
|
|
delete $self->{_relationship_data}; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _ident_cond { |
89
|
0
|
|
|
0
|
|
|
my ($class) = @_; |
90
|
0
|
|
|
|
|
|
return join(" AND ", map { "$_ = ?" } $class->primary_columns); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _flesh { |
94
|
0
|
|
|
0
|
|
|
my ($self, @groups) = @_; |
95
|
0
|
0
|
|
|
|
|
@groups = ('All') unless @groups; |
96
|
0
|
|
|
|
|
|
my %want; |
97
|
0
|
|
|
|
|
|
$want{$_} = 1 for map { keys %{$self->_column_groups->{$_}} } @groups; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if (my @want = grep { !exists $self->{'_column_data'}{$_} } keys %want) { |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $cursor = $self->result_source->storage->select( |
100
|
|
|
|
|
|
|
$self->result_source->name, \@want, |
101
|
|
|
|
|
|
|
\$self->_ident_cond, { bind => [ $self->_ident_values ] }); |
102
|
|
|
|
|
|
|
#my $sth = $self->storage->select($self->_table_name, \@want, |
103
|
|
|
|
|
|
|
# $self->ident_condition); |
104
|
|
|
|
|
|
|
# Not sure why the first one works and this doesn't :( |
105
|
0
|
|
|
|
|
|
my @val = $cursor->next; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return unless @val; # object must have been deleted from the database |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach my $w (@want) { |
110
|
0
|
|
|
|
|
|
$self->{'_column_data'}{$w} = shift @val; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |