| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Class::PK; |
|
2
|
|
|
|
|
|
|
|
|
3
|
379
|
|
|
379
|
|
149602
|
use strict; |
|
|
379
|
|
|
|
|
817
|
|
|
|
379
|
|
|
|
|
10669
|
|
|
4
|
379
|
|
|
379
|
|
1570
|
use warnings; |
|
|
379
|
|
|
|
|
739
|
|
|
|
379
|
|
|
|
|
9973
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
379
|
|
|
379
|
|
1473
|
use base qw/DBIx::Class::Row/; |
|
|
379
|
|
|
|
|
650
|
|
|
|
379
|
|
|
|
|
215034
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
DBIx::Class::PK - Primary Key class |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This class contains methods for handling primary keys and methods |
|
17
|
|
|
|
|
|
|
depending on them. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 METHODS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 id |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Returns the primary key(s) for a row. Can't be called as |
|
26
|
|
|
|
|
|
|
a class method. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub id { |
|
31
|
343
|
|
|
343
|
1
|
5326
|
my ($self) = @_; |
|
32
|
343
|
50
|
|
|
|
955
|
$self->throw_exception( "Can't call id() as a class method" ) |
|
33
|
|
|
|
|
|
|
unless ref $self; |
|
34
|
343
|
|
|
|
|
1334
|
my @id_vals = $self->_ident_values; |
|
35
|
343
|
100
|
|
|
|
2254
|
return (wantarray ? @id_vals : $id_vals[0]); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _ident_values { |
|
39
|
1711
|
|
|
1711
|
|
2857
|
my ($self, $use_storage_state) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1711
|
|
|
|
|
2062
|
my (@ids, @missing); |
|
42
|
|
|
|
|
|
|
|
|
43
|
1711
|
|
|
|
|
4468
|
for ($self->result_source->_pri_cols_or_die) { |
|
44
|
|
|
|
|
|
|
push @ids, ($use_storage_state and exists $self->{_column_data_in_storage}{$_}) |
|
45
|
1780
|
100
|
66
|
|
|
10148
|
? $self->{_column_data_in_storage}{$_} |
|
46
|
|
|
|
|
|
|
: $self->get_column($_) |
|
47
|
|
|
|
|
|
|
; |
|
48
|
1780
|
0
|
33
|
|
|
5092
|
push @missing, $_ if (! defined $ids[-1] and ! $self->has_column_loaded ($_) ); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
1711
|
50
|
33
|
|
|
5206
|
if (@missing && $self->in_storage) { |
|
52
|
0
|
|
|
|
|
0
|
$self->throw_exception ( |
|
53
|
|
|
|
|
|
|
'Unable to uniquely identify result object with missing PK columns: ' |
|
54
|
|
|
|
|
|
|
. join (', ', @missing ) |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
1711
|
|
|
|
|
3762
|
return @ids; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 ID |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Returns a unique id string identifying a result object by primary key. |
|
64
|
|
|
|
|
|
|
Used by L and |
|
65
|
|
|
|
|
|
|
L. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item WARNING |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The default C<_create_ID> method used by this function orders the returned |
|
72
|
|
|
|
|
|
|
values by the alphabetical order of the primary column names, B |
|
73
|
|
|
|
|
|
|
the L method, which follows the same order in which columns were fed |
|
74
|
|
|
|
|
|
|
to L. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub ID { |
|
81
|
54
|
|
|
54
|
1
|
95
|
my ($self) = @_; |
|
82
|
54
|
50
|
|
|
|
138
|
$self->throw_exception( "Can't call ID() as a class method" ) |
|
83
|
|
|
|
|
|
|
unless ref $self; |
|
84
|
54
|
50
|
|
|
|
150
|
return undef unless $self->in_storage; |
|
85
|
54
|
|
|
|
|
62
|
return $self->_create_ID(%{$self->ident_condition}); |
|
|
54
|
|
|
|
|
223
|
|
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _create_ID { |
|
89
|
54
|
|
|
54
|
|
118
|
my ($self, %vals) = @_; |
|
90
|
54
|
50
|
|
|
|
93
|
return undef if grep { !defined } values %vals; |
|
|
76
|
|
|
|
|
208
|
|
|
91
|
|
|
|
|
|
|
return join '|', ref $self || $self, $self->result_source->name, |
|
92
|
54
|
|
33
|
|
|
216
|
map { $_ . '=' . $vals{$_} } sort keys %vals; |
|
|
76
|
|
|
|
|
731
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 ident_condition |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $cond = $result_source->ident_condition(); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $cond = $result_source->ident_condition('alias'); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Produces a condition hash to locate a row based on the primary key(s). |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub ident_condition { |
|
106
|
142
|
|
|
142
|
1
|
561
|
shift->_mk_ident_cond(@_); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _storage_ident_condition { |
|
110
|
1228
|
|
|
1228
|
|
4058
|
shift->_mk_ident_cond(shift, 1); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _mk_ident_cond { |
|
114
|
1370
|
|
|
1370
|
|
2109
|
my ($self, $alias, $use_storage_state) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
1370
|
|
|
|
|
3380
|
my @pks = $self->result_source->_pri_cols_or_die; |
|
117
|
1368
|
|
|
|
|
4641
|
my @vals = $self->_ident_values($use_storage_state); |
|
118
|
|
|
|
|
|
|
|
|
119
|
1368
|
|
|
|
|
2156
|
my (%cond, @undef); |
|
120
|
1368
|
100
|
|
|
|
2859
|
my $prefix = defined $alias ? $alias.'.' : ''; |
|
121
|
1368
|
|
|
|
|
2333
|
for my $col (@pks) { |
|
122
|
1437
|
50
|
|
|
|
6024
|
if (! defined ($cond{$prefix.$col} = shift @vals) ) { |
|
123
|
0
|
|
|
|
|
0
|
push @undef, $col; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
1368
|
50
|
33
|
|
|
3653
|
if (@undef && $self->in_storage) { |
|
128
|
0
|
|
|
|
|
0
|
$self->throw_exception ( |
|
129
|
|
|
|
|
|
|
'Unable to construct result object identity condition due to NULL PK columns: ' |
|
130
|
|
|
|
|
|
|
. join (', ', @undef) |
|
131
|
|
|
|
|
|
|
); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
1368
|
|
|
|
|
22386
|
return \%cond; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 FURTHER QUESTIONS? |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Check the list of L. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This module is free software L |
|
144
|
|
|
|
|
|
|
by the L. You can |
|
145
|
|
|
|
|
|
|
redistribute it and/or modify it under the same terms as the |
|
146
|
|
|
|
|
|
|
L. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |