| 1 | package IO::Async::Pg::Results; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | # Constructor from DBI statement handle (eager fetch) | ||||||||||||
| 7 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 8 | 0 | my ($class, $sth) = @_; | |||||||||||
| 9 | |||||||||||||
| 10 | # Fetch all rows eagerly as hashrefs | ||||||||||||
| 11 | 0 | ▶ | my $rows = $sth->fetchall_arrayref({}) // []; | ||||||||||
|
Condition0%0/2
$sth->fetchall_arrayref({}) // []
MC/DC0%0/1
$sth->fetchall_arrayref({}) // []
$sth->fetchall_arrayref({})
Truth table0%0/2
A
A= $sth->fetchall_arrayref({})
| |||||||||||||
| 12 | 0 | ▶ | my $columns = $sth->{NAME} ? [ @{$sth->{NAME}} ] : []; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 13 | 0 | my $rows_affected = $sth->rows; | |||||||||||
| 14 | 0 | $sth->finish; | |||||||||||
| 15 | |||||||||||||
| 16 | 0 | return bless { | |||||||||||
| 17 | rows => $rows, | ||||||||||||
| 18 | columns => $columns, | ||||||||||||
| 19 | count => scalar @$rows, | ||||||||||||
| 20 | rows_affected => $rows_affected, | ||||||||||||
| 21 | }, $class; | ||||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | # Constructor from data (for testing without DBI) | ||||||||||||
| 25 | 10 | ▶ | sub new_from_data { | ||||||||||
|
Subroutine
new_from_data: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||
| 26 | 10 | my ($class, %args) = @_; | |||||||||||
| 27 | |||||||||||||
| 28 | 10 | ▶ | my $rows = $args{rows} // []; | ||||||||||
|
Condition50%1/2
$args{"rows"} // []
MC/DC0%0/1
$args{"rows"} // []
$args{"rows"}
Truth table50%1/2
A
A= $args{"rows"}
| |||||||||||||
| 29 | 10 | ▶ | my $columns = $args{columns} // []; | ||||||||||
|
Condition50%1/2
$args{"columns"} // []
MC/DC0%0/1
$args{"columns"} // []
$args{"columns"}
Truth table50%1/2
A
A= $args{"columns"}
| |||||||||||||
| 30 | |||||||||||||
| 31 | return bless { | ||||||||||||
| 32 | rows => $rows, | ||||||||||||
| 33 | columns => $columns, | ||||||||||||
| 34 | count => scalar @$rows, | ||||||||||||
| 35 | 10 | ▶ | rows_affected => $args{rows_affected} // 0, | ||||||||||
|
Condition100%2/2
$args{"rows_affected"} // 0
MC/DC100%1/1
$args{"rows_affected"} // 0
$args{"rows_affected"}
Truth table100%2/2
A
A= $args{"rows_affected"}
| |||||||||||||
| 36 | }, $class; | ||||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | # All rows as arrayref of hashrefs | ||||||||||||
| 40 | 2 | ▶ | sub rows { shift->{rows} } | ||||||||||
|
Subroutine
rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 41 | |||||||||||||
| 42 | # Column names | ||||||||||||
| 43 | 1 | ▶ | sub columns { shift->{columns} } | ||||||||||
|
Subroutine
columns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | |||||||||||||
| 45 | # Number of rows | ||||||||||||
| 46 | 2 | ▶ | sub count { shift->{count} } | ||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 47 | |||||||||||||
| 48 | # Rows affected by INSERT/UPDATE/DELETE | ||||||||||||
| 49 | 1 | ▶ | sub rows_affected { shift->{rows_affected} } | ||||||||||
|
Subroutine
rows_affected: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 50 | |||||||||||||
| 51 | # First row or undef | ||||||||||||
| 52 | 5 | ▶ | sub first { | ||||||||||
|
Subroutine
first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 53 | 5 | my $self = shift; | |||||||||||
| 54 | 5 | return $self->{rows}[0]; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | # First column of first row (useful for COUNT(*) etc) | ||||||||||||
| 58 | 2 | ▶ | sub scalar { | ||||||||||
|
Subroutine
scalar: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||
| 59 | 2 | my $self = shift; | |||||||||||
| 60 | 2 | my $first = $self->first; | |||||||||||
| 61 | 2 | ▶ | return undef unless $first; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | |||||||||||||
| 63 | # Get first column name and return its value | ||||||||||||
| 64 | 2 | my $col = $self->{columns}[0]; | |||||||||||
| 65 | 2 | ▶ | return $first->{$col} if defined $col; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | # Fallback: return first value in hash | ||||||||||||
| 68 | 0 | my @values = values %$first; | |||||||||||
| 69 | 0 | return $values[0]; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | # True if no rows | ||||||||||||
| 73 | 3 | ▶ | sub is_empty { | ||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 74 | 3 | my $self = shift; | |||||||||||
| 75 | 3 | return $self->{count} == 0; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 2 | 1; | |||||||||||
| 79 | |||||||||||||
| 80 | __END__ | ||||||||||||