blib/lib/DBIx/QuickORM/JoinRow.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 42.8% 6 / 14 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 87.5% 7 / 8 Podpod 50.0% 2 / 4 totaltotal 70.3% 45 / 64 CC 13 SCAR 15.3
CC
13
Cov
71%
init
7.5
init
7.5
row
4.1
CRAP 4.6
« blib/lib/DBIx/QuickORM/Dialect.pm ↑ Summary blib/lib/DBIx/QuickORM/Type/DateTime.pm »
1 package DBIx::QuickORM::JoinRow;
2 305 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 305 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 305 our $VERSION = '0.000032';
6  
7 305 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 305 ▶use Object::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 +aliases
11 +rows
12 <data
13 305 };
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 32 ▶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
BranchTrueFalseTotal
unless ref $self->{"aliases"} eq "ARRAY" 1 31 32
unless ref $self->{"aliases"} eq "ARRAY" 0 0 0
60 0 ▶ croak "'rows' must be a hashref" unless ref($self->{+ROWS}) eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $self->{"rows"} eq "HASH" 0 31 31
unless ref $self->{"rows"} eq "HASH" 0 0 0
61 0 ▶ croak "'data' must be a hashref" unless ref($self->{+DATA}) eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $self->{"data"} eq "HASH" 0 31 31
unless ref $self->{"data"} eq "HASH" 0 0 0
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. Croaks for a
85 name that is not a component.
86  
87 =back
88  
89 =cut
90  
91 43 ▶sub row {
Subroutine row: called CC=4 SCAR=14.0
Pod documented
92 43 my $self = shift;
93 43 my ($name) = @_;
94 43 ▶ croak "The join has no component named '" . ($name // 'undef') . "'" unless defined($name) && grep { $_ eq $name } @{$self->{+ALIASES}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and grep {$_ eq $name;} @{$$self{"aliases"};} 1 42 43
Condition60%3/5
defined $name and grep {$_ eq $name;} @{$$self{"aliases"};}
!ll&&!rl&&r
0142
$name // "undef"
l!l
10
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"};}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $name
Aresult
11
00
95 42 return $self->{+ROWS}->{$name};
96 }
97  
98 305 1;
99  
100 __END__
« blib/lib/DBIx/QuickORM/Dialect.pm ↑ Summary blib/lib/DBIx/QuickORM/Type/DateTime.pm »