blib/lib/DBIO/Storage/DBI/UniqueIdentifier.pm

filter: Statementstmt 90.0% 36 / 40 Branchbran 50.0% 2 / 4 Conditioncond 55.5% 5 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 76.5% 49 / 64 CC 7 SCAR 15.9
CC
7
Cov
81%
_prefetch_autovalues
7.6
_is_guid_type
2.0
BEGIN
1.0
CRAP 4.9
« blib/lib/DBIO/Test/Schema/Artist.pm ↑ Summary blib/lib/DBIO/FilterColumn.pm »
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/
!ll&&!rl&&r
020
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/
ABresult
0X0
100
111
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'}
!ll&&!rl&&r
201
$col_info->{$_}{"data_type"} and $col_info->{$_}{"data_type"} =~ /$GUID_TYPE/
!ll&&!rl&&r
021
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'}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless (defined $guid_method) 0 1 1
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
BranchTrueFalseTotal
if (ref $guid_method eq 'CODE') { } 1 0 1
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__
« blib/lib/DBIO/Test/Schema/Artist.pm ↑ Summary blib/lib/DBIO/FilterColumn.pm »