| 1 | package DBIO::PK; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Primary Key class | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 378 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 378 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 378 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 378 | ▶ | use base qw/DBIO::Row/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 19 | ▶ | sub id { | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||
| 15 | 19 | ▶ | $self->throw_exception( "Can't call id() as a class method" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | unless ref $self; | ||||||||||||||||||||||||||||
| 17 | 19 | my @id_vals = $self->_ident_values; | |||||||||||||||||||||||||||
| 18 | 19 | ▶ | return (wantarray ? @id_vals : $id_vals[0]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 380 | ▶ | sub _ident_values { | ||||||||||||||||||||||||||
|
Subroutine
_ident_values: called CC=8 SCAR=22.8
| |||||||||||||||||||||||||||||
| 23 | 380 | my ($self, $use_storage_state) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 380 | my (@ids, @missing); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 380 | for ($self->result_source->_pri_cols_or_die) { | |||||||||||||||||||||||||||
| 28 | push @ids, ($use_storage_state and exists $self->{_column_data_in_storage}{$_}) | ||||||||||||||||||||||||||||
| 29 | 381 | ▶ | ? $self->{_column_data_in_storage}{$_} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$use_storage_state and exists $self->{"_column_data_in_storage"}{$_}
MC/DC100%2/2
$use_storage_state and exists $self->{"_column_data_in_storage"}{$_}
$use_storage_state
exists $self->{"_column_data_in_storage"}{$_}
Truth table100%3/3
A and B
A= $use_storage_stateB= exists $self->{"_column_data_in_storage"}{$_}
| |||||||||||||||||||||||||||||
| 30 | : $self->get_column($_) | ||||||||||||||||||||||||||||
| 31 | ; | ||||||||||||||||||||||||||||
| 32 | 381 | ▶ | push @missing, $_ if (! defined $ids[-1] and ! $self->has_column_loaded ($_) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ids[-1] or $self->has_column_loaded($_)
MC/DC0%0/2
defined $ids[-1] or $self->has_column_loaded($_)
defined $ids[-1]
$self->has_column_loaded($_)
Truth table33%1/3
A or B
A= defined $ids[-1]B= $self->has_column_loaded($_)
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 380 | ▶ | if (@missing && $self->in_storage) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@missing and $self->in_storage
MC/DC0%0/2
@missing and $self->in_storage
@missing
$self->in_storage
Truth table33%1/3
A and B
A= @missingB= $self->in_storage
| |||||||||||||||||||||||||||||
| 36 | 0 | $self->throw_exception ( | |||||||||||||||||||||||||||
| 37 | 'Unable to uniquely identify result object with missing PK columns: ' | ||||||||||||||||||||||||||||
| 38 | . join (', ', @missing ) | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 380 | return @ids; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub ID { | ||||||||||||||||||||||||||
|
Subroutine
ID: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | $self->throw_exception( "Can't call ID() as a class method" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | unless ref $self; | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return undef unless $self->in_storage; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | return $self->_create_ID(%{$self->ident_condition}); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub _create_ID { | ||||||||||||||||||||||||||
|
Subroutine
_create_ID: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($self, %vals) = @_; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | return undef if grep { !defined } values %vals; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | return join '|', ref $self || $self, $self->result_source->name, | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | map { $_ . '=' . $vals{$_} } sort keys %vals; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | ▶ | sub ident_condition { | ||||||||||||||||||||||||||
|
Subroutine
ident_condition: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 5 | shift->_mk_ident_cond(@_); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 356 | ▶ | sub _storage_ident_condition { | ||||||||||||||||||||||||||
|
Subroutine
_storage_ident_condition: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 356 | shift->_mk_ident_cond(shift, 1); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 361 | ▶ | sub _mk_ident_cond { | ||||||||||||||||||||||||||
|
Subroutine
_mk_ident_cond: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||
| 74 | 361 | my ($self, $alias, $use_storage_state) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 361 | my @pks = $self->result_source->_pri_cols_or_die; | |||||||||||||||||||||||||||
| 77 | 361 | my @vals = $self->_ident_values($use_storage_state); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 361 | my (%cond, @undef); | |||||||||||||||||||||||||||
| 80 | 361 | ▶ | my $prefix = defined $alias ? $alias.'.' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 361 | for my $col (@pks) { | |||||||||||||||||||||||||||
| 82 | 362 | ▶ | if (! defined ($cond{$prefix.$col} = shift @vals) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | push @undef, $col; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 361 | ▶ | if (@undef && $self->in_storage) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@undef and $self->in_storage
MC/DC0%0/2
@undef and $self->in_storage
@undef
$self->in_storage
Truth table33%1/3
A and B
A= @undefB= $self->in_storage
| |||||||||||||||||||||||||||||
| 88 | 0 | $self->throw_exception ( | |||||||||||||||||||||||||||
| 89 | 'Unable to construct result object identity condition due to NULL PK columns: ' | ||||||||||||||||||||||||||||
| 90 | . join (', ', @undef) | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 361 | return \%cond; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 378 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||