| 1 | package DBIx::QuickORM::JoinRow; | ||||||||||||||||||||||||||||||||||||||
| 2 | 260 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 260 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 260 | our $VERSION = '0.000033'; | |||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 260 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 260 | ▶ | use Object::HashBase qw{ | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | +aliases | ||||||||||||||||||||||||||||||||||||||
| 11 | +rows | ||||||||||||||||||||||||||||||||||||||
| 12 | <data | ||||||||||||||||||||||||||||||||||||||
| 13 | 260 | }; | |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | =pod | ||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | DBIx::QuickORM::JoinRow - One row of a join: its component rows and raw data. | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | A row fetched through a join (L<DBIx::QuickORM::Source::Join>). It holds the | ||||||||||||||||||||||||||||||||||||||
| 26 | row of each component, built with that table's row class, and the fetched | ||||||||||||||||||||||||||||||||||||||
| 27 | values. It has no write methods, so write through the component rows. | ||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | my $jrow = $orm->handle('posts')->join('users')->first; | ||||||||||||||||||||||||||||||||||||||
| 32 | my $post = $jrow->row('posts'); | ||||||||||||||||||||||||||||||||||||||
| 33 | my $name = $jrow->row('users')->field('name'); | ||||||||||||||||||||||||||||||||||||||
| 34 | my @names = $jrow->aliases; # ('posts', 'users') | ||||||||||||||||||||||||||||||||||||||
| 35 | my $title = $jrow->data->{'posts.title'}; | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | All three are required at construction, and one of the wrong shape croaks. | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | =item $data = $jrow->data | ||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | The fetched values as a hashref keyed C<component.field>. | ||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||
| 47 | =item aliases => \@names | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | =item rows => {$name => $row_or_undef} | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | Read through the C<aliases> and C<row> methods. | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | =back | ||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | 37 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | croak "'aliases' must be an arrayref" unless ref($self->{+ALIASES}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | croak "'rows' must be a hashref" unless ref($self->{+ROWS}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak "'data' must be a hashref" unless ref($self->{+DATA}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | =item @names = $jrow->aliases | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | The component names, in join order. | ||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | =back | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub aliases { @{$_[0]->{+ALIASES}} } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | =pod | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | =item $row = $jrow->row($name) | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | The component's row, or undef when a left join matched nothing. | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | my @rows = $orm->handle('users')->left_join('posts')->all; | ||||||||||||||||||||||||||||||||||||||
| 87 | my @quiet = grep { !defined $_->row('posts') } @rows; # users with no posts | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | Croaks for a name that is not a component. | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 49 | ▶ | sub row { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
row: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 96 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 97 | 49 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||
| 98 | 49 | ▶ | croak "The join has no component named '" . ($name // 'undef') . "'" unless defined($name) && grep { $_ eq $name } @{$self->{+ALIASES}}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $name and grep {$_ eq $name;} @{$$self{"aliases"};}
$name // "undef"
MC/DC50%1/2
defined $name and grep {$_ eq $name;} @{$$self{"aliases"};}
defined $name
grep {$_ eq $name;} @{$$self{"aliases"};}
MC/DC0%0/1
$name // "undef"
$name
Truth table66%2/3
A and B
A= defined $nameB= grep {$_ eq $name;} @{$$self{"aliases"};}
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||
| 99 | 48 | return $self->{+ROWS}->{$name}; | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | 260 | 1; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||||||||||||