| 1 | package DBIx::Class::Async::Row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 101 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 101 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 101 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 101 | our $VERSION = qv('v1.2.0'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 101 | our $AUTHORITY = 'cpan:MANWAR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | DBIx::Class::Async::Row - Asynchronous Row object representing a single database record. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Version v1.2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Rows are typically retrieved via a ResultSet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | my $future = $rs->find(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $future->on_done(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | my $user = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Access columns (non-blocking if pre-inflated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | say $user->username; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Update columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | $user->last_login('2026-02-02'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Persist changes asynchronously | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | $user->update->on_done(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | say "User updated!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Traverse relationships (Returns a Future) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $user->posts->all->on_done(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | my $posts = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | say "User has " . scalar(@$posts) . " posts."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | This class provides an asynchronous interface to individual database rows. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | It maintains internal state regarding "dirty" (unsaved) columns and handles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | the hand-off to the background worker for all I/O operations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =head2 in_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | my $bool = $row->in_storage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $row->in_storage(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Returns or sets whether the row is considered "in the database." Setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | this to true clears the "dirty" status of all columns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 PERSISTENCE METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =head2 update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $row->update({ status => 'active' })->then(sub { ... }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | If the row is in storage, dispatches an C<UPDATE> command to the worker for any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | modified (dirty) columns. Returns a L<Future> resolving to the updated row object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | =head2 delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $row->delete->on_done(sub { say "Gone!" }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Asynchronously deletes the row from the database using its Primary Key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Upon success, C<in_storage> is set to 0. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head2 discard_changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $row->discard_changes->then(sub { ... }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Re-fetches the row data from the database, overwriting any local unsaved changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | and resetting the "dirty" flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =head2 copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $row->copy({ username => 'new_user' })->then(sub { ... }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Creates a new record in the database using the current row's data as a template, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | excluding Primary Keys unless explicitly provided in the changes hashref. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | =head2 insert_query | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | my ($sql, @bind) = $row->insert_query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | my $query = $row->insert_query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | Returns the SQL and bind values that would be generated by an insert operation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | without actually executing it. The row must be in_storage(false) state. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | my $row = $schema->resultset('User')->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | name => 'Alice', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | email => 'alice@example.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | my ($sql, @bind) = $row->insert_query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # $sql = \'INSERT INTO users (name, email) VALUES (?, ?)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # @bind = ('Alice', 'alice@example.com') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Now actually insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | $row->insert->get; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =head1 DATA ACCESSORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 get_column / set_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | my $val = $row->get_column('email'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | $row->set_column('email', 'new@example.com'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Standard DBIC-style column accessors. C<set_column> marks the column as "dirty." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | =head2 get_dirty_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | my %dirty = $row->get_dirty_columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Returns a list of key-value pairs for columns that have been modified but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | not yet saved to the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =head1 RELATIONSHIPS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =head2 related_resultset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | my $rel_rs = $row->related_resultset('posts'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | Returns a L<DBIx::Class::Async::ResultSet> for the named relationship, pre-configured | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | with the foreign key join condition. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =head2 create_related | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $row->create_related('posts', { title => 'New Post' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | Shorthand for C<< $row->related_resultset($rel)->create($data) >>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 101 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 101 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 101 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 101 | ▶ | use Future; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 101 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # PRIVATE CONSTANTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Protects internal attributes from being treated as database columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 101 | my $INTERNAL_KEYS = qr/^(?:_.*|async_db|source_name|schema|_inflation_map)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1139 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=34.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1139 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1139 | ▶ | croak "Missing required argument: schema_instance" unless $args{schema_instance}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1139 | ▶ | croak "Missing required argument: async_db" unless $args{async_db}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1139 | ▶ | croak "Missing required argument: source_name" unless $args{source_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1139 | ▶ | croak "Missing required argument: row_data" unless $args{row_data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1139 | ▶ | my $in_storage = delete $args{in_storage} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{"in_storage"} // 0
MC/DC0%0/1
delete $args{"in_storage"} // 0
delete $args{"in_storage"}
Truth table50%1/2
A
A= delete $args{"in_storage"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1139 | ▶ | my $data = $args{row_data} || $args{_data} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$args{'row_data'} || $args{'_data'} || {}
$args{"row_data"} or $args{"_data"}
MC/DC0%0/2
$args{'row_data'} || $args{'_data'} || {}
$args{"row_data"}
$args{"_data"}
Truth table33%1/3
A or B
A= $args{"row_data"}B= $args{"_data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Capture pre-inflated relationship objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1139 | ▶ | my $rel_data = $args{relationship_data} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"relationship_data"} // {}
MC/DC0%0/1
$args{"relationship_data"} // {}
$args{"relationship_data"}
Truth table50%1/2
A
A= $args{"relationship_data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | _schema_instance => $args{schema_instance}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | _async_db => $args{async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | _source_name => $args{source_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | _result_source => $args{result_source} // undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1139 | ▶ | _data => { %$data }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"result_source"} // undef
MC/DC0%0/1
$args{"result_source"} // undef
$args{"result_source"}
Truth table50%1/2
A
A= $args{"result_source"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | _dirty => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | _inflated => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | _related => { %$rel_data }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | _in_storage => $in_storage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | _inflation_map => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1139 | $self->_ensure_accessors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # WARM-UP: Pre-calculate metadata and shadow plain columns for speed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1139 | my $source = $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1139 | ▶ | if ($source && ref($source) && eval { $source->can('has_column') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$source and ref $source and eval {
do {
$source->can("has_column")
}
}
$source and ref $source
MC/DC0%0/3
$source and ref $source and eval {
do {
$source->can("has_column")
}
}
$source
ref $source
eval {
do {
$source->can("has_column")
}
}
Truth table25%1/4
A and B and C
A= $sourceB= ref $sourceC= eval {
do {
$source->can("has_column")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # 1. Shadow physical columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1139 | foreach my $col (keys %$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Skip internal plumbing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 7228 | ▶ | next if $self->_is_internal($col); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 7228 | ▶ | if ($source->has_column($col)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 7227 | my $info = $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7227 | ▶ | my $inflator = $info->{inflate} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$info->{"inflate"} // 0
MC/DC0%0/1
$info->{"inflate"} // 0
$info->{"inflate"}
Truth table50%1/2
A
A= $info->{"inflate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 7227 | $self->{_inflation_map}{$col} = $inflator; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # If NO inflator, shadow to top-level for direct hash-key speed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 7227 | ▶ | if (!$inflator) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 7227 | $self->{$col} = $data->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # 2. Shadow relationship objects for fast access | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1139 | foreach my $rel (keys %$rel_data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $self->{$rel} = $rel_data->{$rel}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Mark as "inflated" so accessors don't try to re-fetch from DB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->{_inflation_map}{$rel} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1139 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=10 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | my ($self, $changes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 11 | ▶ | $changes //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$changes //= {}
MC/DC0%0/1
$changes //= {}
$changes
Truth table50%1/2
A
A= $changes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 11 | my $source = $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # 1. Get ONLY keys that are valid database columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 11 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 11 | foreach my $col ($source->columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Check _data first (clean storage), then top-level (hack storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 88 | ▶ | if (exists $self->{_data}{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 88 | $data{$col} = $self->{_data}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | elsif (exists $self->{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # Ensure we don't accidentally copy our own management objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # if a column happened to have the same name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | next if $col =~ /^(?:async_db|schema|source_name|_source)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $data{$col} = $self->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # 2. Remove Primary Keys (unless specifically overridden in $changes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | foreach my $pk ($source->primary_columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 11 | ▶ | delete $data{$pk} unless exists $changes->{$pk}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # 3. Apply user changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | foreach my $col (keys %$changes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 22 | $data{$col} = $changes->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # 4. Use the schema to create the copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 11 | my $schema = $self->{_schema_instance}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 11 | ▶ | unless ($schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # If no schema instance, we need to get it from somewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # This shouldn't happen if Row was created properly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | croak "Cannot copy: Row object has no schema instance reference"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 11 | return $schema->resultset($self->{_source_name})->create(\%data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 34 | ▶ | sub create_related { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_related: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 34 | my ($self, $rel_name, $col_data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 34 | my $rs = $self->related_resultset($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | my $rs_cond = (ref $rs->{cond} eq 'HASH') ? $rs->{cond} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | : (ref $rs->{_cond} eq 'HASH') ? $rs->{_cond} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 34 | ▶ | : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 34 | ▶ | my $merged_data = { %$rs_cond, %{$col_data || {}} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$col_data || {}
MC/DC0%0/1
$col_data || {}
$col_data
Truth table50%1/2
A
A= $col_data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 34 | return $rs->create($merged_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 17 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=6 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 17 | ▶ | unless ($self->in_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # Idempotent - already deleted, just return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | return Future->done(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 12 | my $db = $self->{_async_db}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 12 | my $source_name = $self->{_source_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 12 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 12 | my ($pk_col) = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | my $id_val = $self->{_data}{$pk_col} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | // ($self->can($pk_col) ? $self->$pk_col : undef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 12 | ▶ | // $self->{$pk_col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
($self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)) // $self->{$pk_col}
$self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)
MC/DC0%0/3
($self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)) // $self->{$pk_col}
$self->{"_data"}{$pk_col}
($self->can($pk_col) ? $self->$pk_col : undef)
$self->{$pk_col}
Truth table25%1/4
A // B // C
A= $self->{"_data"}{$pk_col}B= ($self->can($pk_col) ? $self->$pk_col : undef)C= $self->{$pk_col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 12 | ▶ | if (!defined $id_val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return Future->fail("Cannot delete: Primary key ($pk_col) is missing"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | return DBIx::Class::Async::_call_worker( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $db, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 'delete', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | source_name => $source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | cond => { $pk_col => $id_val } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 12 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 12 | my $result = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Mark as not in storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 12 | $self->in_storage(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 12 | return Future->done($result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 12 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 5 | ▶ | sub discard_changes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
discard_changes: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # 1. Primary Key Validation (Matching your old design) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | my $source = $self->{_schema_instance}->resultset($self->{_source_name})->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 5 | my @pk = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | ▶ | croak("Cannot discard changes on row without primary key") unless @pk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | ▶ | croak("Composite primary keys not yet supported") if @pk > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | my $pk_col = $pk[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 5 | my $id = $self->{_data}{$pk_col}; # Using new internal _data structure | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5 | ▶ | croak("Cannot discard changes: primary key value is undefined") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # 2. Fetch fresh data using the new re-anchored design | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # We use find($id) which returns a Future containing a new Row object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | ▶ | return $self->_spawn_rs->search({ $pk_col => $id })->first->then(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | my ($fresh_row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # In the new design, find() returns undef or a Row object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 5 | ▶ | unless ($fresh_row) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | return Future->fail("Row vanished from database", 'db_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # 3. Synchronise internal state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # We extract the columns from the fresh object into this one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | my $raw_data = $fresh_row->{_data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | $self->{_data} = { %$raw_data }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | $self->{_dirty} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # 4. Refresh speed shadows (Warm-up optimisation) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | $self->_ensure_accessors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | return Future->done($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 674 | ▶ | sub get_column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_column: called CC=16 SCAR=36.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 674 | my ($self, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # 1. Fast-track internal plumbing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 674 | ▶ | return $self->{$col} if $self->_is_internal($col); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # 2. Return cached inflated value if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 674 | ▶ | return $self->{_inflated}{$col} if exists $self->{_inflated}{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # 3. Discovery & Exception Handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 674 | ▶ | if (!exists $self->{_inflation_map}{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 5 | my $source = $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # If it's not in data AND not in schema, trigger DBIC exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 5 | ▶ | if ($source && !$source->has_column($col) && !exists $self->{_data}{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$source and not $source->has_column($col) and not exists $self->{"_data"}{$col}
$source and not $source->has_column($col)
MC/DC66%2/3
$source and not $source->has_column($col) and not exists $self->{"_data"}{$col}
$source
not $source->has_column($col)
not exists $self->{"_data"}{$col}
Truth table75%3/4
A and not(B) and not(C)
A= $sourceB= not $source->has_column($col)C= not exists $self->{"_data"}{$col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # Calling column_info on a non-existent column triggers the "No such column" croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | return $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | ▶ | if ($source && $source->has_column($col)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$source and $source->has_column($col)
MC/DC50%1/2
$source and $source->has_column($col)
$source
$source->has_column($col)
Truth table66%2/3
A and B
A= $sourceB= $source->has_column($col)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | ▶ | $self->{_inflation_map}{$col} = $source->column_info($col)->{inflate} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$source->column_info($col)->{"inflate"} // 0
MC/DC0%0/1
$source->column_info($col)->{"inflate"} // 0
$source->column_info($col)->{"inflate"}
Truth table50%1/2
A
A= $source->column_info($col)->{"inflate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | $self->{_inflation_map}{$col} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 673 | my $raw = $self->{_data}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 673 | my $inflator = $self->{_inflation_map}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # 4. Inflate if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 673 | ▶ | if ($inflator && defined $raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$inflator and defined $raw
MC/DC0%0/2
$inflator and defined $raw
$inflator
defined $raw
Truth table33%1/3
A and B
A= $inflatorB= defined $raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # Check if already inflated via shadow key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ("$raw" =~ /^HASH\(0x/ && ref $self->{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"$raw" =~ /^HASH\(0x/u and ref $self->{$col}
MC/DC0%0/2
"$raw" =~ /^HASH\(0x/u and ref $self->{$col}
"$raw" =~ /^HASH\(0x/u
ref $self->{$col}
Truth table0%0/3
A and B
A= "$raw" =~ /^HASH\(0x/uB= ref $self->{$col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return $self->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $inflated = eval { $inflator->("$raw", $self) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (!$@ && defined $inflated) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $@ and defined $inflated
MC/DC0%0/2
not $@ and defined $inflated
not $@
defined $inflated
Truth table0%0/3
not(A) and B
A= not $@B= defined $inflated
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->{_inflated}{$col} = $inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->{$col} = $inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return $inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 673 | return $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 313 | ▶ | sub get_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_columns: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 313 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 313 | ▶ | my $data = $self->{_data} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_data'} || {}
MC/DC0%0/1
$self->{'_data'} || {}
$self->{'_data'}
Truth table50%1/2
A
A= $self->{'_data'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # 1. Get the list of valid column names from the source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 313 | my @valid_cols = $self->_get_source->columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # 2. Only extract keys that are actual database columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 313 | my %cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 313 | foreach my $col (@valid_cols) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2099 | ▶ | if (exists $data->{$col}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2082 | $cols{$col} = $data->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 313 | ▶ | return wantarray ? %cols : \%cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 31 | ▶ | sub get_dirty_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_dirty_columns: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 31 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 31 | my %dirty_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 31 | foreach my $column (keys %{$self->{_dirty}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 37 | $dirty_values{$column} = $self->{_data}{$column}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 31 | ▶ | return wantarray ? %dirty_values : \%dirty_values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | ▶ | sub get_inflated_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_inflated_columns: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | my %inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | foreach my $col (keys %{$self->{_data}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 7 | $inflated{$col} = $self->get_column($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | return %inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | ▶ | sub id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=11 SCAR=46.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | ▶ | croak("id() cannot be called as a class method") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | unless ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $source = $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | unless ($source && ref($source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$source and ref $source and eval {
do {
$source->can("primary_columns")
}
}
$source and ref $source
MC/DC0%0/3
$source and ref $source and eval {
do {
$source->can("primary_columns")
}
}
$source
ref $source
eval {
do {
$source->can("primary_columns")
}
}
Truth table0%0/4
A and B and C
A= $sourceB= ref $sourceC= eval {
do {
$source->can("primary_columns")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | && eval { $source->can('primary_columns') }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | croak("Could not retrieve valid ResultSource for " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | ($self->{_source_name} // 'Unknown') . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"_source_name"} // "Unknown"
MC/DC0%0/1
$self->{"_source_name"} // "Unknown"
$self->{"_source_name"}
Truth table0%0/2
A
A= $self->{"_source_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ". Source is either missing or unblessed."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my @pk_columns = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | croak("No primary key defined for " . $self->{source_name}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | unless @pk_columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my @pk_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | foreach my $col (@pk_columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $val = $self->get_column($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # Warn if primary key is undefined (usually means row not in storage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | unless (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | carp("Primary key column '$col' is undefined for " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $self->{source_name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | push @pk_values, $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # Return based on context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # List context: return list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return @pk_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # Scalar context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | if (@pk_values == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Single primary key: return the value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return $pk_values[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # Composite primary key: return arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return \@pk_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 5 | ▶ | sub ident_condition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ident_condition: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | my $source = $self->{_result_source} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | ▶ | || $self->{_schema_instance}->resultset($self->{_source_name})->result_source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'_result_source'} || $self->{'_schema_instance'}->resultset($self->{'_source_name'})->result_source
MC/DC0%0/2
$self->{'_result_source'} || $self->{'_schema_instance'}->resultset($self->{'_source_name'})->result_source
$self->{'_result_source'}
$self->{'_schema_instance'}->resultset($self->{'_source_name'})->result_source
Truth table33%1/3
A || B
A= $self->{'_result_source'}B= $self->{'_schema_instance'}->resultset($self->{'_source_name'})->result_source
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 5 | my @pks = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | ▶ | croak "ident_condition failed: No primary keys defined for " . $self->{_source_name} unless @pks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # Return a HASHREF instead of a list to make it easier to use elsewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 5 | return { map { $_ => $self->{_data}{$_} } @pks }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # If the row is already in the database, DBIC behavior is to throw an error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # or no-op. Here we follow the safer path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | if ($self->in_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | return Future->fail("Check failed: count of objects to be inserted is 0 (already in storage)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # update_or_insert handles the actual DB communication and state flipping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | return $self->update_or_insert; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | ▶ | sub insert_or_update { shift->update_or_insert(@_); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_or_update: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 718 | ▶ | sub in_storage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in_storage: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 718 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 718 | ▶ | if (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 622 | ▶ | $self->{_in_storage} = $val ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # If it's in storage, it's no longer 'dirty' (unsaved changes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 622 | ▶ | $self->{_dirty} = {} if $self->{_in_storage}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 718 | ▶ | return $self->{_in_storage} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_in_storage"} // 0
MC/DC0%0/1
$self->{"_in_storage"} // 0
$self->{"_in_storage"}
Truth table50%1/2
A
A= $self->{"_in_storage"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | sub insert_query { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_query: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | Carp::croak("insert_query can only be called on rows not yet in storage") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | if $self->in_storage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my $bridge = $self->{_async_db}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my $schema_class = $bridge->{_schema_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | unless ($schema_class->can('resultset')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | eval { DBIx::Class::Async::_safe_require_class($schema_class) } or die "insert_query: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # Silence warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | warn @_ unless $_[0] =~ /undetermined_driver|sql_limit_dialect|GenericSubQ/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | unless ($bridge->{_metadata_schema}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | $bridge->{_metadata_schema} = $schema_class->connect('dbi:NullP:'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | my $storage = $bridge->{_metadata_schema}->storage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | my $source = $bridge->{_metadata_schema}->source($self->{_source_name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | my %to_insert = $self->get_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my ($sql, @bind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $table = $source->from; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | my @cols = sort keys %to_insert; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | my @placeholders = ('?') x @cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | my $cols_sql = join(', ', @cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $vals_sql = join(', ', @placeholders); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | $sql = \"INSERT INTO $table ($cols_sql) VALUES ($vals_sql)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | @bind = @to_insert{@cols}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | croak("Failed to generate insert SQL: $@"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | return wantarray ? ($sql, @bind) : \[ $sql, @bind ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 23 | ▶ | sub is_column_changed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_column_changed: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 23 | my ($self, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 23 | ▶ | croak("column name required") unless defined $column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 23 | ▶ | return exists $self->{_dirty}{$column} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | sub is_column_dirty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_column_dirty: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my ($self, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | return exists $self->{_dirty}{$column} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 2 | ▶ | sub make_column_dirty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_column_dirty: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 2 | my ($self, $column) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 2 | ▶ | croak("column name required") unless defined $column; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 2 | $self->{_dirty}{$column} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 41 | ▶ | sub related_resultset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
related_resultset: called CC=11 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 41 | my ($self, $rel_name, $cond, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # 1. Get metadata from the schema class (no temp_schema needed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 41 | my $source_obj = $self->{_async_db}->{_schema_class}->source($self->{_source_name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 41 | my $rel_info = $source_obj->relationship_info($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 41 | ▶ | die "No such relationship '$rel_name' on " . $self->{_source_name} unless $rel_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # 2. Build the Join Condition (the foreign keys) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 40 | my $join_cond = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 40 | ▶ | if ($rel_info->{cond}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 40 | ▶ | while (my ($foreign_col, $self_col) = each %{$rel_info->{cond}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 40 | $foreign_col =~ s/^foreign\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 40 | $self_col =~ s/^self\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 40 | $join_cond->{$foreign_col} = $self->get_column($self_col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # 3. Finalise condition and source name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 40 | ▶ | my $final_cond = { %$join_cond, %{ $cond || {} } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cond || {}
MC/DC0%0/1
$cond || {}
$cond
Truth table50%1/2
A
A= $cond
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | # Carry forward the relationship where condition. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # rel_info->{attrs}{where} was previously silently discarded here, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # meaning datetime filters (or any where on the relationship definition) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # were never applied when traversing via the row accessor. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 40 | ▶ | my $final_attrs = { %{ $attrs || {} } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs || {}
MC/DC0%0/1
$attrs || {}
$attrs
Truth table50%1/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 40 | ▶ | if (my $rel_where = $rel_info->{attrs}{where}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | if (exists $final_attrs->{where}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $final_attrs->{where} = { -and => [ $final_attrs->{where}, $rel_where ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | $final_attrs->{where} = $rel_where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 40 | my $foreign_source_name = $rel_info->{source}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 40 | ▶ | my $target_result_class = $rel_info->{class} || $foreign_source_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rel_info->{'class'} || $foreign_source_name
MC/DC0%0/2
$rel_info->{'class'} || $foreign_source_name
$rel_info->{'class'}
$foreign_source_name
Truth table33%1/3
A || B
A= $rel_info->{'class'}B= $foreign_source_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # 4. Path A: Prefetched Data Cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 40 | ▶ | if (exists $self->{_relationship_data}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 3 | my $prefetched = $self->{_relationship_data}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | my $rs = DBIx::Class::Async::ResultSet->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | schema_instance => $self->{_schema_instance}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | async_db => $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | source_name => $foreign_source_name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | cond => $final_cond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | result_class => $target_result_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | attrs => $final_attrs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 3 | $rs->{_is_prefetched} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 3 | ▶ | $rs->{_entries} = ref $prefetched eq 'ARRAY' ? $prefetched : [$prefetched]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 3 | return $rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # 5. Path B: Standard Async Database Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | return DBIx::Class::Async::ResultSet->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | schema_instance => $self->{_schema_instance}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | async_db => $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 37 | source_name => $foreign_source_name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | result_class => $target_result_class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | cond => $final_cond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | attrs => $final_attrs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1198 | ▶ | sub result_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
result_source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1198 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1198 | return $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 70 | ▶ | sub set_column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_column: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 70 | my ($self, $col, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 70 | ▶ | if (!defined $col || $col eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $col or $col eq ""
MC/DC50%1/2
not defined $col or $col eq ""
not defined $col
$col eq ""
Truth table66%2/3
not(A) or B
A= not defined $colB= $col eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 1 | Carp::croak("Column name required for set_column"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # If someone tries to set 'async_db' or '_source', we return early | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # to protect the object's plumbing and prevent "dirty" poisoning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 69 | ▶ | return $value if $self->_is_internal($col); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # 1. Capture types before any operations occur | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 69 | my $old = $self->{_data}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 69 | ▶ | my $old_ref = ref($old) || 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $old || 'SCALAR'
MC/DC0%0/1
ref $old || 'SCALAR'
ref $old
Truth table50%1/2
A
A= ref $old
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 69 | ▶ | my $new_ref = ref($value) || 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $value || 'SCALAR'
MC/DC100%1/1
ref $value || 'SCALAR'
ref $value
Truth table100%2/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 69 | my $changed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 69 | ▶ | if (!defined $old && defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
not defined $old and defined $value
MC/DC100%2/2
not defined $old and defined $value
not defined $old
defined $value
Truth table100%3/3
not(A) and B
A= not defined $oldB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | ▶ | } elsif (defined $old && !defined $value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $old and not defined $value
MC/DC100%2/2
defined $old and not defined $value
defined $old
not defined $value
Truth table100%3/3
A and not(B)
A= defined $oldB= not defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 1 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | ▶ | } elsif (defined $old && defined $value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $old and defined $value
MC/DC50%1/2
defined $old and defined $value
defined $old
defined $value
Truth table66%2/3
A and B
A= defined $oldB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 66 | ▶ | if ($old_ref ne 'SCALAR' || $new_ref ne 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$old_ref ne "SCALAR" or $new_ref ne "SCALAR"
MC/DC50%1/2
$old_ref ne "SCALAR" or $new_ref ne "SCALAR"
$old_ref ne "SCALAR"
$new_ref ne "SCALAR"
Truth table66%2/3
A or B
A= $old_ref ne "SCALAR"B= $new_ref ne "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 2 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # Safe to use string comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 64 | ▶ | if ($old ne $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 50 | $changed = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 69 | ▶ | if ($changed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 54 | $self->{_data}{$col} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 54 | $self->{_dirty}{$col} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # Clear the inflated cache so the next 'get_column' re-inflates the new data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 54 | delete $self->{_inflated}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # We delete the top-level key so it doesn't "shadow" the new data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 54 | delete $self->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 69 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 5 | ▶ | sub set_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_columns: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 5 | my ($self, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 5 | ▶ | croak("hashref of column-value pairs required") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $values and ref $values eq "HASH"
MC/DC50%1/2
defined $values and ref $values eq "HASH"
defined $values
ref $values eq "HASH"
Truth table66%2/3
A and B
A= defined $valuesB= ref $values eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | unless defined $values && ref $values eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 3 | ▶ | while (my ($column, $value) = each %$values) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 7 | $self->set_column($column, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 19 | ▶ | sub _update_internal_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_internal_state: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 19 | my ($self, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # 1. Update the internal data hash directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # This assumes $res contains the updated column data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 19 | ▶ | if (ref $res eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | foreach my $col (keys %$res) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | $self->{_data}{$col} = $res->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # Optionally update the shadow variable if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 0 | ▶ | $self->{$col} = $res->{$col} if exists $self->{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # 2. Update state flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 19 | $self->{_in_storage} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 19 | delete $self->{_dirty}; # Clear dirty flags | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 19 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 20 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 20 | my ($self, $values) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 20 | ▶ | if (!$self->{_schema_instance}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # Return a failed future to prevent further cascading failures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return Future->fail("ResultSet is not initialized with a schema instance."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 20 | ▶ | unless ($self->in_storage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | return Future->fail("Cannot update row: not in storage. Did you mean to call insert or update_or_insert?"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 19 | ▶ | if ($values) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 15 | ▶ | croak("Usage: update({ col => val })") unless ref $values eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 15 | foreach my $col (keys %$values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 25 | $self->set_column($col, $values->{$col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 19 | ▶ | return $self->update_or_insert->on_done(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | # 1. Get the source and necessary metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 19 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 19 | my $schema = $source->schema; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 19 | my $source_name = $source->source_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # 2. Explicitly create the custom ResultSet object using your new() method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | my $rs = DBIx::Class::Async::ResultSet->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | schema_instance => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | source_name => $source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | async_db => $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 19 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # 3. Cache Invalidation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | # It is impossible to invalidate the cache key by reconstructing it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # from the primary key of the row because cache keys are generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # by using the complete criteria from a search query (as explained | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # in CPANSec CWE-639 fix through ResultSet::_generate_cache_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # method). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # Therefore, a read, such as search({ id => $id, owner => $user }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # is cached using a key that is impossible to reconstruct from an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # update that is row-level. Instead of invalidating individual cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # keys, one should invalidate the source completely, analogous to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # the writing operation of the ResultSet class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 19 | $rs->clear_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 19 | return $self->_update_internal_state($rs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 29 | ▶ | sub update_or_insert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_or_insert: called CC=20 SCAR=39.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 29 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 29 | my $async_db = $self->{_async_db}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 29 | my $source_name = $self->{_source_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 29 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 29 | my ($pk_col) = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # 1. Apply changes to the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 29 | ▶ | if ($data && ref $data eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$data and ref $data eq "HASH"
MC/DC50%1/2
$data and ref $data eq "HASH"
$data
ref $data eq "HASH"
Truth table66%2/3
A and B
A= $dataB= ref $data eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1 | foreach my $col (keys %$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 2 | $self->set_column($col, $data->{$col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 29 | my $is_update = $self->in_storage; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # 2. Prepare Payload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 29 | ▶ | my %raw_payload = $is_update ? $self->get_dirty_columns : %{ $self->{_data} // {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"_data"} // {}
MC/DC0%0/1
$self->{"_data"} // {}
$self->{"_data"}
Truth table50%1/2
A
A= $self->{"_data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 29 | my %to_save; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 29 | foreach my $col (keys %raw_payload) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | # If it's not in _inflated, fall back to the raw value in %raw_payload. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 38 | ▶ | my $val = exists $self->{_inflated}{$col} ? $self->{_inflated}{$col} : $raw_payload{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 38 | my $info = $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # If a deflate handler exists and we have a reference, turn it into a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 38 | ▶ | if ($info && $info->{deflate} && defined $val && ref $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$info and $info->{"deflate"} and defined $val and ref $val
$info and $info->{"deflate"} and defined $val
$info and $info->{"deflate"}
MC/DC0%0/4
$info and $info->{"deflate"} and defined $val and ref $val
$info
$info->{"deflate"}
defined $val
ref $val
Truth table20%1/5
A and B and C and D
A= $infoB= $info->{"deflate"}C= defined $valD= ref $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | $val = $info->{deflate}->($val, $self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 38 | $to_save{$col} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | # 3. Success handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 26 | ▶ | my $on_success = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=22 SCAR=43.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 26 | my ($res) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | # We check if it's an object FIRST before asking what kind of object it is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 26 | ▶ | if (blessed($res) && $res->isa('DBIx::Class::Exception')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
MC/DC0%0/2
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
builtin::blessed($res)
$res->isa("DBIx::Class::Exception")
Truth table33%1/3
A and B
A= builtin::blessed($res)B= $res->isa("DBIx::Class::Exception")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | return Future->fail($res->msg, 'db_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # Also check for the HASH-style error envelope which we saw in your logs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 26 | ▶ | if (ref $res eq 'HASH' && ($res->{error} || $res->{__error})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $res eq "HASH" and $res->{"error"} || $res->{"__error"}
$res->{"error"} or $res->{"__error"}
MC/DC0%0/3
ref $res eq "HASH" and $res->{"error"} || $res->{"__error"}
ref $res eq "HASH"
$res->{"error"}
$res->{"__error"}
Truth table50%2/4
A and B or C
A= ref $res eq "HASH"B= $res->{"error"}C= $res->{"__error"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | ▶ | my $err = $res->{error} // $res->{__error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$res->{"error"} // $res->{"__error"}
MC/DC0%0/2
$res->{"error"} // $res->{"__error"}
$res->{"error"}
$res->{"__error"}
Truth table0%0/3
A // B
A= $res->{"error"}B= $res->{"__error"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | return Future->fail($err, 'db_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # Normalise data source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 26 | my $final_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 26 | ▶ | if (ref $res && ref $res eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $res and ref $res eq "HASH"
MC/DC50%1/2
ref $res and ref $res eq "HASH"
ref $res
ref $res eq "HASH"
Truth table66%2/3
A and B
A= ref $resB= ref $res eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 4 | $final_data = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | elsif (ref $res && eval { $res->can('get_columns') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $res and eval {
do {
$res->can("get_columns")
}
}
MC/DC0%0/2
ref $res and eval {
do {
$res->can("get_columns")
}
}
ref $res
eval {
do {
$res->can("get_columns")
}
}
Truth table33%1/3
A and B
A= ref $resB= eval {
do {
$res->can("get_columns")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # Handle case where $res is another Row object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | my %cols = $res->get_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 0 | $final_data = \%cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # Scalar result (ID) or fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 22 | $final_data = { %to_save }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 22 | ▶ | if (!$is_update && defined $res && !ref $res && $pk_col) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not $is_update and defined $res and not ref $res and $pk_col
not $is_update and defined $res and not ref $res
not $is_update and defined $res
MC/DC0%0/4
not $is_update and defined $res and not ref $res and $pk_col
not $is_update
defined $res
not ref $res
$pk_col
Truth table20%1/5
not(A) and B and not(C) and D
A= not $is_updateB= defined $resC= not ref $resD= $pk_col
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | $final_data->{$pk_col} = $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 26 | $self->{_in_storage} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 26 | $self->in_storage(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 26 | foreach my $col (keys %$final_data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 56 | my $new_val = $final_data->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # 1. Update core data first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 56 | $self->{_data}{$col} = $new_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | # 1. Clear caches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 56 | delete $self->{_inflated}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 56 | delete $self->{_dirty}{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # 3. Handle the Shadow Key with a "Column Only" safety check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 56 | ▶ | my $source = $self->can('_get_source') ? $self->_get_source : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | # CRITICAL: Only call column_info IF the source confirms it is a real column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # This skips 'schema', '_source', 'async_db', and relationships. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 56 | ▶ | if ($source && $source->has_column($col)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$source and $source->has_column($col)
MC/DC0%0/2
$source and $source->has_column($col)
$source
$source->has_column($col)
Truth table33%1/3
A and B
A= $sourceB= $source->has_column($col)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 56 | my $info = $source->column_info($col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 56 | ▶ | if ($info && $info->{inflate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$info and $info->{"inflate"}
MC/DC0%0/2
$info and $info->{"inflate"}
$info
$info->{"inflate"}
Truth table33%1/3
A and B
A= $infoB= $info->{"inflate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # For inflated cols, delete shadow to force get_column() to run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 0 | delete $self->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # For standard columns, update the shadow. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 56 | $self->{$col} = $new_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # If it's an internal attribute or relationship, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # just update the shadow if it already exists, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # but NEVER ask column_info about it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | $self->{$col} = $new_val if exists $self->{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 26 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 29 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | # 4. Dispatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 29 | ▶ | if ($is_update) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 24 | ▶ | return Future->done($self) unless keys %to_save; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | my $id_val = $self->{_data}{$pk_col} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | // ( $self->can($pk_col) ? $self->$pk_col : undef ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 22 | ▶ | // $self->{$pk_col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
($self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)) // $self->{$pk_col}
$self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)
MC/DC0%0/3
($self->{"_data"}{$pk_col} // ($self->can($pk_col) ? $self->$pk_col : undef)) // $self->{$pk_col}
$self->{"_data"}{$pk_col}
($self->can($pk_col) ? $self->$pk_col : undef)
$self->{$pk_col}
Truth table25%1/4
A // B // C
A= $self->{"_data"}{$pk_col}B= ($self->can($pk_col) ? $self->$pk_col : undef)C= $self->{$pk_col}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | if (ref $id_val && eval { $id_val->can('get_column') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $id_val and eval {
do {
$id_val->can("get_column")
}
}
MC/DC0%0/2
ref $id_val and eval {
do {
$id_val->can("get_column")
}
}
ref $id_val
eval {
do {
$id_val->can("get_column")
}
}
Truth table33%1/3
A and B
A= ref $id_valB= eval {
do {
$id_val->can("get_column")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | $id_val = $id_val->get_column($pk_col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 22 | ▶ | if (!defined $id_val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | return Future->fail( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | "Cannot update row: Primary key ($pk_col) is missing", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | "logic_error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | return DBIx::Class::Async::_call_worker( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 'update', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | source_name => $source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | cond => { $pk_col => $id_val }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | updates => \%to_save | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 22 | ▶ | })->then(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 22 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | # Handle worker exceptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 22 | ▶ | if (blessed($res) && $res->isa('DBIx::Class::Exception')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
MC/DC0%0/2
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
builtin::blessed($res)
$res->isa("DBIx::Class::Exception")
Truth table33%1/3
A and B
A= builtin::blessed($res)B= $res->isa("DBIx::Class::Exception")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | return Future->fail("$res", 'db_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 22 | return $on_success->($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 22 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | return DBIx::Class::Async::_call_worker( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 'create', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | source_name => $source_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | data => \%to_save | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 4 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 4 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | # 1. Catch Exception objects from the Worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 4 | ▶ | if (blessed($res) && $res->isa('DBIx::Class::Exception')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
MC/DC0%0/2
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
builtin::blessed($res)
$res->isa("DBIx::Class::Exception")
Truth table33%1/3
A and B
A= builtin::blessed($res)B= $res->isa("DBIx::Class::Exception")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | return Future->fail("$res", 'db_error'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | # 2. Hand off to your excellent on_success handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | # This will set in_storage(1) and clear dirty flags. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 4 | return $on_success->($res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 1 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=11 SCAR=40.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 1 | my ($method) = $AUTOLOAD =~ /([^:]+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | # 1. Immediate exit for core/Future/Perl methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 1 | ▶ | return if $method =~ /^(?:DESTROY|AWAIT_\w+|can|isa|then|get|on_\w+|failure|else|CLONE)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | # 2. Handle Columns (Getter/Setter) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | # Ensure _get_source retrieves the metadata from the parent's schema cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 1 | my $source = eval { $self->_get_source }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 1 | ▶ | if ($source && $source->has_column($method)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$source and $source->has_column($method)
MC/DC0%0/2
$source and $source->has_column($method)
$source
$source->has_column($method)
Truth table33%1/3
A and B
A= $sourceB= $source->has_column($method)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 101 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 101 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | my $accessor = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | my ($inner_self, $new_val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | my $col_info = $inner_self->result_source->column_info($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | # SETTER MODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | delete $inner_self->{_inflated}{$method}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | my $to_store = $new_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | if ($col_info->{deflate} && defined $new_val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$col_info->{"deflate"} and defined $new_val
MC/DC0%0/2
$col_info->{"deflate"} and defined $new_val
$col_info->{"deflate"}
defined $new_val
Truth table0%0/3
A and B
A= $col_info->{"deflate"}B= defined $new_val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | $to_store = $col_info->{deflate}->($new_val, $inner_self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 0 | $inner_self->set_column($method, $to_store); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | ▶ | if ($col_info->{inflate} && ref $new_val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$col_info->{"inflate"} and ref $new_val
MC/DC0%0/2
$col_info->{"inflate"} and ref $new_val
$col_info->{"inflate"}
ref $new_val
Truth table0%0/3
A and B
A= $col_info->{"inflate"}B= ref $new_val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | $inner_self->{_inflated}{$method} = $new_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | return $new_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | # GETTER MODE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | return $inner_self->{_inflated}{$method} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | ▶ | if exists $inner_self->{_inflated}{$method}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | my $raw = $inner_self->get_column($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | ▶ | if ($col_info->{inflate} && defined $raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$col_info->{"inflate"} and defined $raw
MC/DC0%0/2
$col_info->{"inflate"} and defined $raw
$col_info->{"inflate"}
defined $raw
Truth table0%0/3
A and B
A= $col_info->{"inflate"}B= defined $raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | my $inflated = $col_info->{inflate}->($raw, $inner_self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # Handle potential double-inflation edge cases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | ▶ | if (!ref($inflated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $inflated and defined $inflated and $inflated =~ /^mailto:mailto:/u
not ref $inflated and defined $inflated
MC/DC0%0/3
not ref $inflated and defined $inflated and $inflated =~ /^mailto:mailto:/u
not ref $inflated
defined $inflated
$inflated =~ /^mailto:mailto:/u
Truth table0%0/4
not(A) and B and C
A= not ref $inflatedB= defined $inflatedC= $inflated =~ /^mailto:mailto:/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | && defined($inflated) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | && $inflated =~ /^mailto:mailto:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | $inner_self->{_inflated}{$method} = $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | return $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | $inner_self->{_inflated}{$method} = $inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | return $inflated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # Install into the specific class (likely the Anon hybrid class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | my $target_class = ref($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | *{"${target_class}::$method"} = $accessor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | return $self->$method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # 3. Handle Relationships | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 1 | ▶ | if ($source && $source->can('relationship_info')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$source and $source->can("relationship_info")
MC/DC0%0/2
$source and $source->can("relationship_info")
$source
$source->can("relationship_info")
Truth table33%1/3
A and B
A= $sourceB= $source->can("relationship_info")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 1 | my $rel_info = $source->relationship_info($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 1 | ▶ | if ($rel_info) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 101 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 101 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | *{"${class}::$method"} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | my ($current_row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | ▶ | my $row_id = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$current_row->get_column("id")
}
} // "unknown"
MC/DC0%0/1
eval {
do {
$current_row->get_column("id")
}
} // "unknown"
eval {
do {
$current_row->get_column("id")
}
}
Truth table0%0/2
A
A= eval {
do {
$current_row->get_column("id")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | $current_row->get_column('id') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | } // 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | # Check if the relationship data exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | if (exists $current_row->{_relationship_data}{$method}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my $prefetched = $current_row->{_relationship_data}{$method}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | if (($rel_info->{attrs}{accessor} // '') ne 'multi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$rel_info->{"attrs"}{"accessor"} // ""
MC/DC0%0/1
$rel_info->{"attrs"}{"accessor"} // ""
$rel_info->{"attrs"}{"accessor"}
Truth table0%0/2
A
A= $rel_info->{"attrs"}{"accessor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | ▶ | if (Scalar::Util::blessed($prefetched)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | return Future->done($prefetched); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | if (ref($prefetched) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | my $rs = $current_row->{_schema_instance}->resultset($rel_info->{source}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | my $obj = $rs->new_result($prefetched); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | $current_row->{_relationship_data}{$method} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | return Future->done($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | return Future->done($prefetched); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 0 | return $prefetched; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | return $current_row->related_resultset($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | return $self->$method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | # 4. Fallback for non-column data already in the buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 1 | ▶ | if (exists $self->{_data}{$method} && !@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"_data"}{$method} and not @_
MC/DC0%0/2
exists $self->{"_data"}{$method} and not @_
exists $self->{"_data"}{$method}
not @_
Truth table33%1/3
A and not(B)
A= exists $self->{"_data"}{$method}B= not @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | return $self->{_data}{$method}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | # THE HIJACK GUARD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | # If we reached here, Async::Row doesn't recognise this as a DB column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | # We check if a custom class further up the @ISA chain has this method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | # 'can' looks through the entire inheritance tree (MRO) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 1 | my $next_method = $self->can($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 1 | ▶ | if ($next_method && $next_method != \&AUTOLOAD) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next_method and $next_method != \&DBIx::Class::Async::Row::AUTOLOAD
MC/DC0%0/2
$next_method and $next_method != \&DBIx::Class::Async::Row::AUTOLOAD
$next_method
$next_method != \&DBIx::Class::Async::Row::AUTOLOAD
Truth table33%1/3
A and B
A= $next_methodB= $next_method != \&DBIx::Class::Async::Row::AUTOLOAD
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | # We found the real method (e.g., My::Custom::User::hello_name)! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | # Use goto to jump into it, preserving the caller context. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | unshift @_, $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | goto &$next_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | # 5. Exception handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1 | croak(sprintf( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | "Method '%s' not found in package '%s'. " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | "(Can't locate object method via AUTOLOAD. " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | "Is it a missing column or relationship in your ResultSource?)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | $method, ref($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | =head1 DESTROY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | # Called automatically when object is destroyed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | Destructor method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # Nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | =head1 INTERNAL METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | These methods are for internal use and are documented for completeness. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 5 | ▶ | sub _spawn_rs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spawn_rs: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | die "Cannot spawn ResultSet: missing _schema_instance or _source_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 5 | ▶ | unless $self->{_schema_instance} && $self->{_source_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_schema_instance"} and $self->{"_source_name"}
MC/DC0%0/2
$self->{"_schema_instance"} and $self->{"_source_name"}
$self->{"_schema_instance"}
$self->{"_source_name"}
Truth table33%1/3
A and B
A= $self->{"_schema_instance"}B= $self->{"_source_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | return DBIx::Class::Async::ResultSet->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | schema_instance => $self->{_schema_instance}, # Match ResultSet's new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | async_db => $self->{_async_db}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | source_name => $self->{_source_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 5 | cond => $self->ident_condition, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | ▶ | sub _mark_clean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_clean: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | $self->{_dirty} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | =head2 _build_relationship_accessor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | my $coderef = $row->_build_relationship_accessor($method, $rel_info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | Builds an accessor for a relationship that checks for prefetched data first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | then falls back to lazy loading if needed. For has_many relationships, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | ResultSet object is cached in the row. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | ▶ | sub _build_relationship_accessor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_relationship_accessor: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | my ($self, $rel_name, $rel_info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 0 | ▶ | my $rel_type = $rel_info->{attrs}{accessor} || 'single'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rel_info->{'attrs'}{'accessor'} || 'single'
MC/DC0%0/1
$rel_info->{'attrs'}{'accessor'} || 'single'
$rel_info->{'attrs'}{'accessor'}
Truth table0%0/2
A
A= $rel_info->{'attrs'}{'accessor'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | my $cond = $rel_info->{cond}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | ▶ | if ($rel_type eq 'single' || $rel_type eq 'filter') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$rel_type eq "single" or $rel_type eq "filter"
MC/DC0%0/2
$rel_type eq "single" or $rel_type eq "filter"
$rel_type eq "single"
$rel_type eq "filter"
Truth table0%0/3
A or B
A= $rel_type eq "single"B= $rel_type eq "filter"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | # belongs_to or might_have relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | my $row = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | # 1. CHECK FOR PREFETCHED DATA FIRST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | ▶ | if (exists $row->{_prefetched} && exists $row->{_prefetched}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $row->{"_prefetched"} and exists $row->{"_prefetched"}{$rel_name}
MC/DC0%0/2
exists $row->{"_prefetched"} and exists $row->{"_prefetched"}{$rel_name}
exists $row->{"_prefetched"}
exists $row->{"_prefetched"}{$rel_name}
Truth table0%0/3
A and B
A= exists $row->{"_prefetched"}B= exists $row->{"_prefetched"}{$rel_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | my $prefetched = $row->{_prefetched}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | ▶ | return Future->done($prefetched) if blessed($prefetched); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 0 | return Future->done(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | # 2. LAZY LOAD: Extract foreign key from condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 0 | my $fk = $row->_extract_foreign_key($cond); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | ▶ | return Future->done(undef) unless $fk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $fk_value = $row->get_column($fk->{self}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | ▶ | return Future->done(undef) unless defined $fk_value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | # 3. Fetch related row asynchronously via schema->resultset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 0 | my $rel_source = $row->_get_source->related_source($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | my $rel_rs = $row->{schema}->resultset($rel_source->source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | return $rel_rs->find({ $fk->{foreign} => $fk_value }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | elsif ($rel_type eq 'multi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | # has_many relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | my $row = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | ▶ | my $extra_cond = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | # Cache key for this relationship (includes extra conditions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | my $cache_key = $rel_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | ▶ | if (%$extra_cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | # If there are extra conditions, create a unique cache key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 0 | $cache_key .= '_' . Data::Dumper::Dumper($extra_cond); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | # 1. CHECK FOR CACHED RESULTSET (without extra conditions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | # Return cached ResultSet if it exists and no extra conditions were provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | ▶ | if (!%$extra_cond && exists $row->{_relationship_cache} && exists $row->{_relationship_cache}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not %$extra_cond and exists $row->{"_relationship_cache"} and exists $row->{"_relationship_cache"}{$rel_name}
not %$extra_cond and exists $row->{"_relationship_cache"}
MC/DC0%0/3
not %$extra_cond and exists $row->{"_relationship_cache"} and exists $row->{"_relationship_cache"}{$rel_name}
not %$extra_cond
exists $row->{"_relationship_cache"}
exists $row->{"_relationship_cache"}{$rel_name}
Truth table0%0/4
not(A) and B and C
A= not %$extra_condB= exists $row->{"_relationship_cache"}C= exists $row->{"_relationship_cache"}{$rel_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | return $row->{_relationship_cache}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | # 2. CHECK FOR PREFETCHED DATA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 0 | ▶ | if (exists $row->{_prefetched} && exists $row->{_prefetched}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $row->{"_prefetched"} and exists $row->{"_prefetched"}{$rel_name}
MC/DC0%0/2
exists $row->{"_prefetched"} and exists $row->{"_prefetched"}{$rel_name}
exists $row->{"_prefetched"}
exists $row->{"_prefetched"}{$rel_name}
Truth table0%0/3
A and B
A= exists $row->{"_prefetched"}B= exists $row->{"_prefetched"}{$rel_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | my $prefetched_rs = $row->{_prefetched}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | # If extra conditions are provided, filter the prefetched data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | ▶ | if (%$extra_cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | # Don't cache filtered ResultSets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | return $prefetched_rs->search($extra_cond); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | # Cache the prefetched ResultSet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | ▶ | $row->{_relationship_cache} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$row->{"_relationship_cache"} ||= {}
MC/DC0%0/1
$row->{"_relationship_cache"} ||= {}
$row->{"_relationship_cache"}
Truth table0%0/2
A
A= $row->{"_relationship_cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | $row->{_relationship_cache}{$rel_name} = $prefetched_rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | return $prefetched_rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | # 3. LAZY LOAD: Build the relationship condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 0 | my $fk = $row->_extract_foreign_key($cond); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | ▶ | unless ($fk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | my $rel_source = $row->_get_source->related_source($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | my $rs = $row->{schema}->resultset($rel_source->source_name)->search({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | # Don't cache if we couldn't extract FK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | return $rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 0 | my $fk_value = $row->get_column($fk->{self}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 0 | my $related_cond = { $fk->{foreign} => $fk_value, %$extra_cond }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | # 4. Create new ResultSet for lazy loading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | my $rel_source = $row->_get_source->related_source($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | my $rs = $row->{async_db}->resultset($rel_source->source_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | # 5. Cache the ResultSet (only if no extra conditions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | ▶ | if (!%$extra_cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 0 | ▶ | $row->{_relationship_cache} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$row->{"_relationship_cache"} ||= {}
MC/DC0%0/1
$row->{"_relationship_cache"} ||= {}
$row->{"_relationship_cache"}
Truth table0%0/2
A
A= $row->{"_relationship_cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 0 | $row->{_relationship_cache}{$rel_name} = $rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 0 | return $rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | # Default fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 0 | Carp::croak("Unknown relationship type for '$rel_name'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | =head2 _ensure_accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | $row->_ensure_accessors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | Creates accessor methods for all columns in the result source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 2281 | ▶ | sub _ensure_accessors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_accessors: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 2281 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 2281 | my $source = $self->_get_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 2281 | ▶ | return unless blessed($source) && $source->can('can'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($source) and $source->can("can")
MC/DC0%0/2
builtin::blessed($source) and $source->can("can")
builtin::blessed($source)
$source->can("can")
Truth table33%1/3
A and B
A= builtin::blessed($source)B= $source->can("can")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 2281 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 2281 | ▶ | return unless $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | # 1. Handle Columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 2281 | ▶ | if ($source->can('columns')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 2281 | foreach my $col ($source->columns) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 101 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 15159 | ▶ | next if defined &{"${class}::$col"}; # Skip if already installed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 1249 | my $column_name = $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 101 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 1249 | ▶ | *{"${class}::$column_name"} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 468 | my $inner = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 468 | ▶ | return @_ ? $inner->set_column($column_name, shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | : $inner->get_column($column_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 1249 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | # 2. Handle Relationships | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 2281 | ▶ | if ($source->can('relationships')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 2281 | foreach my $rel ($source->relationships) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 101 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 101 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | # Force redefine even if it exists (to clobber DBIC's sync method) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 2233 | my $rel_name = $rel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 2233 | my $rel_info = $source->relationship_info($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 2233 | ▶ | *{"${class}::$rel_name"} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 15 | my ($inner, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | # PRIORITY: If we have a prefetched object, return it - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | # UNLESS the relationship has a where condition containing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | # raw SQL refs (e.g. \'datetime("now")'). Such conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | # cannot be evaluated in Perl, so we must skip the cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | # and let the DB apply the filter via a fresh async fetch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | # This fixes the RT#63709-style silent drop where datetime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | # filters on has_many relationships were ignored entirely. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 15 | ▶ | if (exists $inner->{_related}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 2 | my $rel_where = $rel_info->{attrs}{where}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 2 | ▶ | return $inner->{_related}{$rel_name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rel_where and _where_has_sql_refs($rel_where)
MC/DC0%0/2
$rel_where and _where_has_sql_refs($rel_where)
$rel_where
_where_has_sql_refs($rel_where)
Truth table33%1/3
A and B
A= $rel_whereB= _where_has_sql_refs($rel_where)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | unless $rel_where && _where_has_sql_refs($rel_where); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | # FALLBACK: Perform async fetch if not prefetched, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | # or if the relationship where contains raw SQL refs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 13 | return $inner->_fetch_relationship_async($rel_name, $rel_info, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 2233 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | # Returns true if a where hashref contains any raw SQL scalar refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | # such as \'datetime("now")' that cannot be evaluated in Perl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 2 | ▶ | sub _where_has_sql_refs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where_has_sql_refs: called CC=7 SCAR=21.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 2 | my ($where) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 2 | ▶ | return 0 unless ref $where eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 2 | for my $val (values %$where) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 2 | ▶ | return 1 if ref $val eq 'SCALAR' || ref $val eq 'REF'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $val eq "SCALAR" or ref $val eq "REF"
MC/DC50%1/2
ref $val eq "SCALAR" or ref $val eq "REF"
ref $val eq "SCALAR"
ref $val eq "REF"
Truth table66%2/3
A or B
A= ref $val eq "SCALAR"B= ref $val eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 1 | ▶ | return 1 if ref $val eq 'HASH' && _where_has_sql_refs($val); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $val eq "HASH" and _where_has_sql_refs($val)
MC/DC0%0/2
ref $val eq "HASH" and _where_has_sql_refs($val)
ref $val eq "HASH"
_where_has_sql_refs($val)
Truth table33%1/3
A and B
A= ref $val eq "HASH"B= _where_has_sql_refs($val)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 1138 | ▶ | sub _install_prefetch_accessors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install_prefetch_accessors: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 1138 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 1138 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 1138 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 1138 | ▶ | foreach my $rel_name (keys %{$self->{_relationship_data} // {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_relationship_data"} // {}
MC/DC0%0/1
$self->{"_relationship_data"} // {}
$self->{"_relationship_data"}
Truth table50%1/2
A
A= $self->{"_relationship_data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 14 | my $rel_info = $source->relationship_info($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 14 | ▶ | next unless $rel_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 101 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 101 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 14 | ▶ | *{"${class}::$rel_name"} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 11 | my ($inner_self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 11 | my $data = $inner_self->{_relationship_data}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | # Check if this is a 'multi' (has_many) relationship | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 11 | ▶ | my $is_multi = ($rel_info->{attrs}{accessor} // '') eq 'multi'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rel_info->{"attrs"}{"accessor"} // ""
MC/DC0%0/1
$rel_info->{"attrs"}{"accessor"} // ""
$rel_info->{"attrs"}{"accessor"}
Truth table50%1/2
A
A= $rel_info->{"attrs"}{"accessor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 11 | ▶ | if ($is_multi) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | # For 'multi', the prefetch logic in ResultSet.pm should have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | # already converted the raw data into a ResultSet object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | # If it didn't, we fallback to a normal related_resultset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 4 | ▶ | return $data if Scalar::Util::blessed($data) && $data->isa('DBIx::Class::Async::ResultSet'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($data) and $data->isa("DBIx::Class::Async::ResultSet")
MC/DC50%1/2
builtin::blessed($data) and $data->isa("DBIx::Class::Async::ResultSet")
builtin::blessed($data)
$data->isa("DBIx::Class::Async::ResultSet")
Truth table66%2/3
A and B
A= builtin::blessed($data)B= $data->isa("DBIx::Class::Async::ResultSet")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 3 | return $inner_self->related_resultset($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | # Handle Single relationships (belongs_to / user) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | # This is what Order 3 and 4 need. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 7 | ▶ | if (Scalar::Util::blessed($data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | 1 | return Future->done($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 6 | ▶ | if (ref($data) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 6 | my $rs = $inner_self->{_schema_instance}->resultset($rel_info->{source}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 6 | my $obj = $rs->new_result($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 6 | $inner_self->{_relationship_data}{$rel_name} = $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 6 | return Future->done($obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | # Fallback for singles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 0 | ▶ | return Future->done($data) if defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 0 | return $inner_self->related_resultset($rel_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 14 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | 13 | ▶ | sub _fetch_relationship_async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_relationship_async: called CC=15 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 13 | my ($self, $rel_name, $rel_info, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | # 1. Handle Metadata first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 13 | ▶ | $rel_info //= $self->_get_source->relationship_info($rel_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rel_info //= $self->_get_source->relationship_info($rel_name)
MC/DC0%0/2
$rel_info //= $self->_get_source->relationship_info($rel_name)
$rel_info
$self->_get_source->relationship_info($rel_name)
Truth table33%1/3
A //= B
A= $rel_infoB= $self->_get_source->relationship_info($rel_name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 13 | ▶ | my $acc_type = $rel_info->{attrs}{accessor} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rel_info->{"attrs"}{"accessor"} // ""
MC/DC0%0/1
$rel_info->{"attrs"}{"accessor"} // ""
$rel_info->{"attrs"}{"accessor"}
Truth table50%1/2
A
A= $rel_info->{"attrs"}{"accessor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 13 | ▶ | my $is_single = ($acc_type eq 'single' || $acc_type eq 'filter'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$acc_type eq 'single' || $acc_type eq 'filter'
MC/DC50%1/2
$acc_type eq 'single' || $acc_type eq 'filter'
$acc_type eq 'single'
$acc_type eq 'filter'
Truth table66%2/3
A || B
A= $acc_type eq 'single'B= $acc_type eq 'filter'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | # 2. Cache Hit Logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | # Skip cache if relationship has raw SQL refs in where condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | # (e.g. \'datetime("now")') - these cannot be evaluated in Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | # and must go to the DB to be applied correctly every time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 13 | my $rel_where = $rel_info->{attrs}{where}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 13 | ▶ | my $has_sql_where = $rel_where && _where_has_sql_refs($rel_where); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rel_where && _where_has_sql_refs($rel_where)
MC/DC50%1/2
$rel_where && _where_has_sql_refs($rel_where)
$rel_where
_where_has_sql_refs($rel_where)
Truth table66%2/3
A && B
A= $rel_whereB= _where_has_sql_refs($rel_where)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 13 | ▶ | if (!$has_sql_where && exists $self->{_related}{$rel_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $has_sql_where and exists $self->{"_related"}{$rel_name}
MC/DC0%0/2
not $has_sql_where and exists $self->{"_related"}{$rel_name}
not $has_sql_where
exists $self->{"_related"}{$rel_name}
Truth table66%2/3
not(A) and B
A= not $has_sql_whereB= exists $self->{"_related"}{$rel_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 0 | my $cached = $self->{_related}{$rel_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | # ONLY wrap in Future if it's a single row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 0 | ▶ | return $is_single ? Future->done($cached) : $cached; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | # 3. Resolve search params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 13 | my $target_source = $rel_info->{source}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 13 | my $cond = $rel_info->{cond}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 13 | my %search_params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 13 | ▶ | while (my ($f_key, $s_key) = each %$cond) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | 13 | my $f_col = $f_key; $f_col =~ s/^foreign\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 13 | my $s_col = $s_key; $s_col =~ s/^self\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 13 | $search_params{$f_col} = $self->get_column($s_col); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | # 4. Merge relationship where into search attrs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | # Previously rel_info->{attrs}{where} was never passed to search(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | # so datetime filters and any other where on the relationship definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | # were silently dropped on every async fetch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | # Only build %search_attrs if we actually have a rel_where to merge - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | # passing an empty hashref instead of undef can interfere with other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | # attrs-based mechanisms such as _has_dynamic_sql cache detection. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 13 | ▶ | my %search_attrs = %{ $attrs // {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrs // {}
MC/DC0%0/1
$attrs // {}
$attrs
Truth table50%1/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 13 | ▶ | if ($rel_where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 1 | ▶ | if (exists $search_attrs{where}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | 0 | $search_attrs{where} = { -and => [ $search_attrs{where}, $rel_where ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | 1 | $search_attrs{where} = $rel_where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 13 | ▶ | if ($is_single) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | return $self->{_schema_instance}->resultset($target_source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | ->search(\%search_params, { %search_attrs, rows => 1 }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | ->next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 5 | ▶ | ->then(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 5 | my $row = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 5 | ▶ | $self->{_related}{$rel_name} = $row unless $has_sql_where; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 5 | return Future->done($row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 5 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | # Multi returns the RS directly (synchronously). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | # Only pass \%search_attrs if it contains something - passing an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | # empty hashref instead of the original $attrs risks discarding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | # caller-provided attrs such as +select with dynamic SQL, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | # would break _has_dynamic_sql cache detection in ResultSet.pm. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 8 | ▶ | my $effective_attrs = %search_attrs ? \%search_attrs : $attrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 8 | my $rs = $self->{_schema_instance}->resultset($target_source) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | ->search(\%search_params, $effective_attrs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 8 | ▶ | $self->{_related}{$rel_name} = $rs unless $has_sql_where; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 8 | return $rs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | =head2 _extract_foreign_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | Extracts foreign key mapping from a relationship condition. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | 0 | ▶ | sub _extract_foreign_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_foreign_key: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 0 | my ($self, $cond) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 0 | ▶ | return undef unless $cond; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | # Handle simple foreign key condition: { 'foreign.id' => 'self.user_id' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 0 | ▶ | if (ref $cond eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 0 | my ($foreign_col) = keys %$cond; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 0 | my $self_col = $cond->{$foreign_col}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | # Handle case where self_col is a reference (e.g., { '=' => 'self.user_id' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 0 | ▶ | if (ref $self_col eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | # Extract the actual column name from the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | 0 | my ($op, $col) = %$self_col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 0 | $self_col = $col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | # Strip prefixes if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 0 | $foreign_col =~ s/^foreign\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | 0 | ▶ | $self_col =~ s/^self\.// if defined $self_col && !ref $self_col; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self_col and not ref $self_col
MC/DC0%0/2
defined $self_col and not ref $self_col
defined $self_col
not ref $self_col
Truth table0%0/3
A and not(B)
A= defined $self_colB= not ref $self_col
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 0 | foreign => $foreign_col, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | self => $self_col, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | # Handle code ref conditions (more complex relationships) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | # For now, we'll just return undef and let the relationship fail gracefully | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | =head2 _get_primary_key_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | my $pk_info = $row->_get_primary_key_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | Returns information about the primary key(s) for this row. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | =item B<Returns> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | Hash reference with keys: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | - C<columns>: Array reference of primary key column names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | - C<count>: Number of primary key columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | - C<is_composite>: Boolean indicating composite primary key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 0 | ▶ | sub _get_primary_key_info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_primary_key_info: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 0 | ▶ | my $source = $self->_get_source or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | # CRITICAL: Call primary_columns in LIST context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | 0 | my @primary_columns = $source->primary_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 0 | columns => \@primary_columns, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | count => scalar @primary_columns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | is_composite => scalar @primary_columns > 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | =head2 _get_source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | my $source = $row->_get_source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | Returns the result source for this row, loading it lazily if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 5004 | ▶ | sub _get_source { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_source: called CC=6 SCAR=33.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 5004 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | # 1. Return cached source if already found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 5004 | ▶ | return $self->{_result_source} if $self->{_result_source}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | 0 | my $schema = $self->{_schema_instance}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 0 | my $name = $self->{_source_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | # 2. Guard: if we don't have a schema or name, we can't proceed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | 0 | ▶ | return undef unless $schema && $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$schema and $name
MC/DC0%0/2
$schema and $name
$schema
$name
Truth table0%0/3
A and B
A= $schemaB= $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | # 3. Attempt to fetch from the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 0 | my $source = eval { $schema->source($name) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | # 4. Final verification: Only cache if it's a real, blessed object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 0 | ▶ | if ($source && blessed($source)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$source and builtin::blessed($source)
MC/DC0%0/2
$source and builtin::blessed($source)
$source
builtin::blessed($source)
Truth table0%0/3
A and B
A= $sourceB= builtin::blessed($source)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 0 | return $self->{_result_source} = $source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | # REALLY PRIVATE METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | 0 | ▶ | sub _check_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_response: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 0 | my ($self, $res) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | 0 | ▶ | return undef unless ref $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | # 1. Handle DBIx::Class::Exception objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | 0 | ▶ | if (blessed($res) && $res->isa('DBIx::Class::Exception')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
MC/DC0%0/2
builtin::blessed($res) and $res->isa("DBIx::Class::Exception")
builtin::blessed($res)
$res->isa("DBIx::Class::Exception")
Truth table0%0/3
A and B
A= builtin::blessed($res)B= $res->isa("DBIx::Class::Exception")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 0 | return $res->msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | # 2. Handle HashRef error envelopes ({ __error => "..." }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | 0 | ▶ | if (ref $res eq 'HASH' && (my $err = $res->{error} // $res->{__error})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $res eq "HASH" and my $err = $res->{"error"} // $res->{"__error"}
$res->{"error"} // $res->{"__error"}
MC/DC0%0/3
ref $res eq "HASH" and my $err = $res->{"error"} // $res->{"__error"}
ref $res eq "HASH"
$res->{"error"}
$res->{"__error"}
Truth table0%0/4
A and B // C
A= ref $res eq "HASH"B= $res->{"error"}C= $res->{"__error"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 0 | return $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 7971 | ▶ | sub _is_internal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_internal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 7971 | my ($self, $col) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 7971 | return $col =~ $INTERNAL_KEYS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | =head1 PERFORMANCE OPTIMISATIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | =item * Shadow Keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | For performance, non-inflated columns are shadowed directly onto the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | hash, allowing for fast access without method calls. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | =item * Inflation Map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | The object maintains an internal C<_inflation_map> to avoid repeated metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | lookups against the C<ResultSource>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | =item * Warm-up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | The constructor pre-calculates metadata to ensure the first data access is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | as fast as subsequent ones. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | =head1 REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | L<https://github.com/manwar/DBIx-Class-Async> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/DBIx-Class-Async/issues>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | I will be notified and then you'll automatically be notified of progress on your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | perldoc DBIx::Class::Async::Row | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | =item * BUG Report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | L<https://github.com/manwar/DBIx-Class-Async/issues> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | L<http://cpanratings.perl.org/d/DBIx-Class-Async> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | =item * Search MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | L<https://metacpan.org/dist/DBIx-Class-Async/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | Copyright (C) 2026 Mohammad Sajid Anwar. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | This program is free software; you can redistribute it and / or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | the terms of the the Artistic License (2.0). You may obtain a copy of the full | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | license at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | Any use, modification, and distribution of the Standard or Modified Versions is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | governed by this Artistic License.By using, modifying or distributing the Package, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | you accept this license. Do not use, modify, or distribute the Package, if you do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | not accept this license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | If your Modified Version has been derived from a Modified Version made by someone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | other than you,you are nevertheless required to ensure that your Modified Version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | complies with the requirements of this license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | This license does not grant you the right to use any trademark, service mark, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | This license includes the non-exclusive, worldwide, free-of-charge patent license | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | to make, have made, use, offer to sell, sell, import and otherwise transfer the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | Package with respect to any patent claims licensable by the Copyright Holder that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | are necessarily infringed by the Package. If you institute patent litigation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | (including a cross-claim or counterclaim) against any party alleging that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | Package constitutes direct or contributory patent infringement,then this Artistic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | License to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 101 | 1; # End of DBIx::Class::Async::Row | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||