| 1 | package DBIO::Storage::DBI::UniqueIdentifier; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Storage component for RDBMSes supporting GUID types | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use base 'DBIO::Storage::DBI'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 4 | __PACKAGE__->mk_group_accessors(inherited => 'new_guid'); | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 4 | my $GUID_TYPE = qr/^(?:uniqueidentifier(?:str)?|guid)\z/i; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub _is_guid_type { | ||||||||||||||||||||||||||||||||
|
Subroutine
_is_guid_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($self, $data_type) = @_; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 0 | return $data_type =~ $GUID_TYPE; | |||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub _prefetch_autovalues { | ||||||||||||||||||||||||||||||||
|
Subroutine
_prefetch_autovalues: called CC=7 SCAR=20.3
| |||||||||||||||||||||||||||||||||||
| 26 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 27 | 2 | my ($source, $col_info, $to_insert) = @_; | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 2 | my %guid_cols; | |||||||||||||||||||||||||||||||||
| 30 | 2 | my @pk_cols = $source->primary_columns; | |||||||||||||||||||||||||||||||||
| 31 | 2 | my %pk_col_idx; | |||||||||||||||||||||||||||||||||
| 32 | 2 | @pk_col_idx{@pk_cols} = (); | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | my @pk_guids = grep { | ||||||||||||||||||||||||||||||||||
| 35 | 2 | $col_info->{$_}{data_type} | |||||||||||||||||||||||||||||||||
| 36 | && | ||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | $col_info->{$_}{data_type} =~ $GUID_TYPE | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$col_info->{$_}{'data_type'} && $col_info->{$_}{'data_type'} =~ /$GUID_TYPE/
MC/DC0%0/2
$col_info->{$_}{'data_type'} && $col_info->{$_}{'data_type'} =~ /$GUID_TYPE/
$col_info->{$_}{'data_type'}
$col_info->{$_}{'data_type'} =~ /$GUID_TYPE/
Truth table33%1/3
A && B
A= $col_info->{$_}{'data_type'}B= $col_info->{$_}{'data_type'} =~ /$GUID_TYPE/
| |||||||||||||||||||||||||||||||||||
| 38 | } @pk_cols; | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | my @auto_guids = grep { | ||||||||||||||||||||||||||||||||||
| 41 | $col_info->{$_}{data_type} | ||||||||||||||||||||||||||||||||||
| 42 | && | ||||||||||||||||||||||||||||||||||
| 43 | $col_info->{$_}{data_type} =~ $GUID_TYPE | ||||||||||||||||||||||||||||||||||
| 44 | && | ||||||||||||||||||||||||||||||||||
| 45 | $col_info->{$_}{auto_nextval} | ||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | } grep { not exists $pk_col_idx{$_} } $source->columns; | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$col_info->{$_}{'data_type'} && $col_info->{$_}{'data_type'} =~ /$GUID_TYPE/ && $col_info->{$_}{'auto_nextval'}
$col_info->{$_}{"data_type"} and $col_info->{$_}{"data_type"} =~ /$GUID_TYPE/
MC/DC33%1/3
$col_info->{$_}{'data_type'} && $col_info->{$_}{'data_type'} =~ /$GUID_TYPE/ && $col_info->{$_}{'auto_nextval'}
$col_info->{$_}{"data_type"}
$col_info->{$_}{"data_type"} =~ /$GUID_TYPE/
$col_info->{$_}{'auto_nextval'}
Truth table50%2/4
A and B && C
A= $col_info->{$_}{"data_type"}B= $col_info->{$_}{"data_type"} =~ /$GUID_TYPE/C= $col_info->{$_}{'auto_nextval'}
| |||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | my @get_guids_for = | ||||||||||||||||||||||||||||||||||
| 49 | 2 | grep { not exists $to_insert->{$_} } (@pk_guids, @auto_guids); | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 2 | for my $guid_col (@get_guids_for) { | |||||||||||||||||||||||||||||||||
| 52 | 1 | my $new_guid; | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 1 | my $guid_method = $self->new_guid; | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | if (not defined $guid_method) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->throw_exception( | |||||||||||||||||||||||||||||||||
| 58 | 'You must set new_guid() on your storage. See perldoc ' | ||||||||||||||||||||||||||||||||||
| 59 | .'DBIO::Storage::DBI::UniqueIdentifier' | ||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | if (ref $guid_method eq 'CODE') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 1 | $to_insert->{$guid_col} = $guid_method->($self); | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||||
| 67 | 0 | ($to_insert->{$guid_col}) = $self->_get_dbh->selectrow_array("SELECT $guid_method"); | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 2 | return $self->next::method(@_); | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 4 | 1; | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||