| 1 | package Alzabo::Runtime::RowCursor; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Alzabo::Exceptions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Alzabo::Runtime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Params::Validate qw( :all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use base qw( Alzabo::Runtime::Cursor ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 11 | $VERSION = 2.0; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use constant NEW_SPEC => { statement => { isa => 'Alzabo::DriverStatement' }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | table => { isa => 'Alzabo::Runtime::Table' }, | ||||||||||||||||||||||||||||
| 18 | 11 | }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub new | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my %p = validate( @_, NEW_SPEC ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $self = bless { %p, | |||||||||||||||||||||||||||
| 28 | count => 0, | ||||||||||||||||||||||||||||
| 29 | }, $class; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub next | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $row; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # This loop is intended to allow the end caller to ignore rows | ||||||||||||||||||||||||||||
| 41 | # that can't be created because they're not in the table. | ||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||
| 43 | # For example, imagine that query in the statement is looking at | ||||||||||||||||||||||||||||
| 44 | # table 'foo' to get PK values for table 'bar'. If table 'foo' | ||||||||||||||||||||||||||||
| 45 | # has a record indicating that there is a row in 'bar' where PK == | ||||||||||||||||||||||||||||
| 46 | # 1 but no such row actually exists then we want to skip this. | ||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||
| 48 | # If they really want to know we do save the exception. | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | until ( defined $row ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | my @row = $self->{statement}->next; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | last unless @row && grep { defined } @row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@row and grep {defined $_;} @row
MC/DC0%0/2
@row and grep {defined $_;} @row
@row
grep {defined $_;} @row
Truth table0%0/3
A and B
A= @rowB= grep {defined $_;} @row
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my %hash; | |||||||||||||||||||||||||||
| 56 | 0 | my @pk = $self->{table}->primary_key; | |||||||||||||||||||||||||||
| 57 | 0 | @hash{ map { $_->name } @pk } = @row[0..$#pk]; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my %prefetch; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( (my @pre = $self->{table}->prefetch) && @row > @pk ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
my(@pre) = $self->{"table"}->prefetch and @row > @pk
MC/DC0%0/2
my(@pre) = $self->{"table"}->prefetch and @row > @pk
my(@pre) = $self->{"table"}->prefetch
@row > @pk
Truth table0%0/3
A and B
A= my(@pre) = $self->{"table"}->prefetchB= @row > @pk
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 0 | @prefetch{@pre} = @row[$#pk + 1 .. $#row]; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | $row = $self->{table}->row_by_pk( @_, | ||||||||||||||||||||||||||||
| 66 | pk => \%hash, | ||||||||||||||||||||||||||||
| 67 | prefetch => \%prefetch, | ||||||||||||||||||||||||||||
| 68 | 0 | %{ $self->{row_params} }, | |||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | return unless $row; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->{count}++; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return $row; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub all_rows | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
all_rows: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my @rows; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | while ( my $row = $self->next ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 0 | push @rows, $row; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self->{count} = scalar @rows; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return @rows; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 11 | 1; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||