Yancy/Backend.pm

filter: Statementstmt 22.2% 16 / 72 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 16.0% 4 / 25 Podpod 95.0% 19 / 20 totaltotal 22.5% 39 / 173 CC 23 SCAR 44.0
CC
23
Cov
14%
normalize
240.0
id_where
30.0
new
12.0
CRAP 81.8
« Yancy/Backend/MojoDB.pm ↑ Summary Yancy/Backend/Dbic.pm »
1 package Yancy::Backend;
2 1 our $VERSION = '1.088';
3 # ABSTRACT: Interface to a database
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod my $be = Yancy::Backend->new( $url );
8 #pod
9 #pod $result = $be->list( $schema, $where, $options );
10 #pod say "Total: " . $result->{total};
11 #pod say "Name: " . $_->{name} for @{ $result->{items} };
12 #pod
13 #pod $item = $be->get( $schema, $id );
14 #pod $be->set( $schema, $id, $item );
15 #pod $be->delete( $schema, $id );
16 #pod $id = $be->create( $schema, $item );
17 #pod
18 #pod =head1 DESCRIPTION
19 #pod
20 #pod A C<Yancy::Backend> handles talking to the database. Different Yancy
21 #pod backends will support different databases. To use a backend, see
22 #pod L</SUPPORTED BACKENDS>. To make your own backend, see L</METHODS> for
23 #pod the list of methods each backend supports, their arguments, and their
24 #pod return values.
25 #pod
26 #pod =head2 Terminology
27 #pod
28 #pod Yancy backends work with schemas, which are made up of items.
29 #pod A schema is a set of items, like a database table. An item is
30 #pod a single element of a schema, and must be a hashref.
31 #pod
32 #pod =head2 Asynchronous Backends
33 #pod
34 #pod Asynchronous backends implement both a synchronous and an asynchronous
35 #pod API (using promises).
36 #pod
37 #pod =head2 Synchronous-only Backends
38 #pod
39 #pod Synchronous-only backends also implement a promises API for
40 #pod compatibility, but will not perform requests concurrently.
41 #pod
42 #pod =head1 SUPPORTED BACKENDS
43 #pod
44 #pod =over
45 #pod
46 #pod =item * L<Yancy::Backend::Pg> - Postgres backend
47 #pod
48 #pod =item * L<Yancy::Backend::Mysql> - MySQL backend
49 #pod
50 #pod =item * L<Yancy::Backend::Sqlite> - SQLite backend
51 #pod
52 #pod =item * L<Yancy::Backend::Dbic> - L<DBIx::Class> backend
53 #pod
54 #pod =back
55 #pod
56 #pod Other backends are available on CPAN.
57 #pod
58 #pod =over
59 #pod
60 #pod =item * L<Yancy::Backend::Static> - Backend for a static site generator
61 #pod with Markdown.
62 #pod
63 #pod =back
64 #pod
65 #pod =head1 EXTENDING
66 #pod
67 #pod To create your own Yancy::Backend for a new database system, inherit
68 #pod from this class and provide the standard six interface methods: L</get>,
69 #pod L</create>, L</set>, L</list>, L</delete>, and L</read_schema>.
70 #pod
71 #pod There are roles to aid backend development:
72 #pod
73 #pod =over
74 #pod
75 #pod =item * L<Yancy::Backend::Role::DBI> provides some methods based on
76 #pod L<DBI>
77 #pod
78 #pod =item * L<Yancy::Backend::Role::Sync> provides promise-based API methods
79 #pod for databases which are synchronous-only.
80 #pod
81 #pod =back
82 #pod
83 #pod Backends do not have to talk to databases. For an example, see
84 #pod L<Yancy::Backend::Static> for a backend that uses plain files like
85 #pod a static site generator.
86 #pod
87 #pod =cut
88  
89 1 ▶use Mojo::Base '-base';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶use Yancy::Util qw( is_type is_format );
Subroutine BEGIN: called CC=1 SCAR=0.0
92 1 ▶use Mojo::JSON qw( encode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 0 ▶has schema => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
95 0 ▶sub collections {
Subroutine collections: not called CC=1 SCAR=6.9
Pod undocumented
96 0 require Carp;
97 0 Carp::carp( '"collections" method is now "schema"' );
98 0 shift->schema( @_ );
99 }
100  
101 #pod =head1 METHODS
102 #pod
103 #pod =head2 new
104 #pod
105 #pod my $url = 'memory://custom_string';
106 #pod my $be = Yancy::Backend::Memory->new( $url, $schema );
107 #pod
108 #pod Create a new backend object. C<$url> is a string that begins with the
109 #pod backend name followed by a colon. Everything else in the URL is for the
110 #pod backend to use to describe how to connect to the underlying database and
111 #pod any options for the backend object itself.
112 #pod
113 #pod The backend name will be run through C<ucfirst> before being looked up
114 #pod in C<Yancy::Backend::>. For example, C<mysql://...> will use the
115 #pod L<Yancy::Backend::Mysql> module.
116 #pod
117 #pod C<$schema> is a hash reference of schema configuration from the Yancy
118 #pod configuration. See L<Yancy::Guides::Schema> for more information.
119 #pod
120 #pod =cut
121  
122 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
123 0 my ( $class, $driver, $schema ) = @_;
124 0 ▶ if ( $class eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
125 0 return load_backend( $driver, $schema );
126 }
127 0 ▶ return $class->SUPER::new( driver => $driver, schema => $schema // {} );
Condition0%0/2
$schema // {}
l!l
00
MC/DC0%0/1
$schema // {}
$schema
Truth table0%0/2
A
A= $schema
Aresult
11
00
128 }
129  
130 #pod =head2 list
131 #pod
132 #pod my $result = $be->list( $schema, $where, %opt );
133 #pod # { total => ..., items => [ ... ] }
134 #pod
135 #pod Fetch a list of items from a schema. C<$schema> is the
136 #pod schema name.
137 #pod
138 #pod C<$where> is a L<SQL::Abstract where structure|SQL::Abstract/WHERE
139 #pod CLAUSES>.
140 #pod
141 #pod # Search for all Dougs
142 #pod $be->list( 'people', { name => { -like => 'Doug%' } } );
143 #pod # Find adults
144 #pod $be->list( 'people', { age => { '>=' => 18 } } );
145 #pod # Find men we can contact
146 #pod $be->list( 'people', { gender => 'male', contact => 1 } );
147 #pod
148 #pod Additionally, Yancy backends support the following additional
149 #pod keys in the where structure:
150 #pod
151 #pod =over
152 #pod
153 #pod =item -has (EXPERIMENTAL)
154 #pod
155 #pod The C<-has> operator searches inside a data structure (an array or
156 #pod a hash). This operator examines the type of the field being searched to
157 #pod perform the appropriate query.
158 #pod
159 #pod # Create a new page with an array of tags and a hash of author
160 #pod # information
161 #pod $be->create( pages => {
162 #pod title => 'Release v1.481',
163 #pod tags => [ 'release', 'minor' ],
164 #pod author => {
165 #pod name => 'Doug Bell',
166 #pod email => 'doug@example.com',
167 #pod },
168 #pod } );
169 #pod
170 #pod # All pages that have the tag "release"
171 #pod $be->list( pages => { tags => { -has => 'release' } } );
172 #pod
173 #pod # All pages that have both the tags "release" and "major"
174 #pod $be->list( pages => { tags => { -has => [ 'release', 'major' ] } } );
175 #pod
176 #pod # All pages that have the author's name starting with Doug
177 #pod $be->list( pages => { author => { -has => { name => { -like => 'Doug%' } } } } );
178 #pod
179 #pod This is not yet supported by all backends, and may never be supported by
180 #pod some. Postgres has array columns and JSON fields. MySQL has JSON fields.
181 #pod The L<Yancy::Util/match> function matches against Perl data structures.
182 #pod All of these should support C<-has> and C<-not_has> before it can be
183 #pod considered not experimental.
184 #pod
185 #pod =back
186 #pod
187 #pod C<%opt> is a list of name/value pairs with the following keys:
188 #pod
189 #pod =over
190 #pod
191 #pod =item * limit - The number of items to return
192 #pod
193 #pod =item * offset - The number of items to skip
194 #pod
195 #pod =item * order_by - A L<SQL::Abstract order by clause|SQL::Abstract/ORDER BY CLAUSES>
196 #pod
197 #pod =item * join - Join one or more tables using a C<x-foreign-key> field.
198 #pod This can be the name of a foreign key field on this schema, or the name
199 #pod of a table with a foreign key field that refers to this schema. Join
200 #pod multiple tables at the same time by passing an arrayref of joins. Fields
201 #pod in joined tables can be queried by prefixing the join name to the field,
202 #pod separated by a dot.
203 #pod
204 #pod =back
205 #pod
206 #pod # Get the second page of 20 people
207 #pod $be->list( 'people', {}, limit => 20, offset => 20 );
208 #pod # Get the list of people sorted by age, oldest first
209 #pod $be->list( 'people', {}, order_by => { -desc => 'age' } );
210 #pod # Get the list of people sorted by age first, then name (ascending)
211 #pod $be->list( 'people', {}, order_by => [ 'age', 'name' ] );
212 #pod
213 #pod Returns a hashref with two keys:
214 #pod
215 #pod =over
216 #pod
217 #pod =item items
218 #pod
219 #pod An array reference of hash references of item data
220 #pod
221 #pod =item total
222 #pod
223 #pod The total count of items that would be returned without C<limit> or
224 #pod C<offset>.
225 #pod
226 #pod =back
227 #pod
228 #pod =cut
229  
230 0 ▶sub list { ... }
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
231  
232 #pod =head2 list_p
233 #pod
234 #pod my $promise = $be->list_p( $schema, $where, %opt );
235 #pod $promise->then( sub {
236 #pod my ( $result ) = @_;
237 #pod # { total => ..., items => [ ... ] }
238 #pod } );
239 #pod
240 #pod Fetch a list of items asynchronously using promises. Returns a promise that
241 #pod resolves to a hashref with C<items> and C<total> keys. See L</list> for
242 #pod arguments and return values.
243 #pod
244 #pod =cut
245  
246 0 ▶sub list_p { ... }
Subroutine list_p: not called CC=1 SCAR=6.9
Pod documented
247  
248 #pod =head2 get
249 #pod
250 #pod my $item = $be->get( $schema, $id, %opts );
251 #pod
252 #pod Get a single item. C<$schema> is the schema name. C<$id> is the
253 #pod ID of the item to get: Either a string for a single key field, or a
254 #pod hash reference for a composite key. Returns a hashref of item data.
255 #pod
256 #pod C<%opts> is a list of name/value pairs of options with the following
257 #pod names:
258 #pod
259 #pod =over
260 #pod
261 #pod =item join
262 #pod
263 #pod Join one or more tables using a C<x-foreign-key> field. This should be
264 #pod the name of the schema to join, either by a foreign key on this table,
265 #pod or a foreign key on the joined table. Join multiple tables at the same
266 #pod time by passing an arrayref of joins.
267 #pod
268 #pod =cut
269  
270 0 ▶sub get { ... }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
271  
272 #pod =head2 get_p
273 #pod
274 #pod my $promise = $be->get_p( $schema, $id );
275 #pod $promise->then( sub {
276 #pod my ( $item ) = @_;
277 #pod # ...
278 #pod } );
279 #pod
280 #pod Get a single item asynchronously using promises. Returns a promise that
281 #pod resolves to the item. See L</get> for arguments and return values.
282 #pod
283 #pod =cut
284  
285 0 ▶sub get_p { ... }
Subroutine get_p: not called CC=1 SCAR=6.9
Pod documented
286  
287 #pod =head2 set
288 #pod
289 #pod my $success = $be->set( $schema, $id, $item );
290 #pod
291 #pod Update an item. C<$schema> is the schema name. C<$id> is the ID of the
292 #pod item to update: Either a string for a single key field, or a hash
293 #pod reference for a composite key. C<$item> is the item's data to set.
294 #pod Returns a boolean that is true if a row with the given ID was found and
295 #pod updated, false otherwise.
296 #pod
297 #pod Currently the values of the data cannot be references, only simple
298 #pod scalars or JSON booleans.
299 #pod
300 #pod =cut
301  
302 0 ▶sub set { ... }
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
303  
304 #pod =head2 set_p
305 #pod
306 #pod my $promise = $be->set_p( $schema, $id );
307 #pod $promise->then( sub {
308 #pod my ( $success ) = @_;
309 #pod # ...
310 #pod } );
311 #pod
312 #pod Update a single item asynchronously using promises. Returns a promise
313 #pod that resolves to a boolean indicating if the row was updated. See
314 #pod L</set> for arguments and return values.
315 #pod
316 #pod =cut
317  
318 0 ▶sub set_p { ... }
Subroutine set_p: not called CC=1 SCAR=6.9
Pod documented
319  
320 #pod =head2 create
321 #pod
322 #pod my $id = $be->create( $schema, $item );
323 #pod
324 #pod Create a new item. C<$schema> is the schema name. C<$item> is
325 #pod the item's data. Returns the ID of the row created suitable to be passed
326 #pod in to C<the get() method|/get>.
327 #pod
328 #pod Currently the values of the data cannot be references, only simple
329 #pod scalars or JSON booleans.
330 #pod
331 #pod =cut
332  
333 0 ▶sub create { ... }
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
334  
335 #pod =head2 create_p
336 #pod
337 #pod my $promise = $be->create_p( $schema, $item );
338 #pod $promise->then( sub {
339 #pod my ( $id ) = @_;
340 #pod # ...
341 #pod } );
342 #pod
343 #pod Create a new item asynchronously using promises. Returns a promise that
344 #pod resolves to the ID of the newly-created item. See L</create> for
345 #pod arguments and return values.
346 #pod
347 #pod =cut
348  
349 0 ▶sub create_p { ... }
Subroutine create_p: not called CC=1 SCAR=6.9
Pod documented
350  
351 #pod =head2 delete
352 #pod
353 #pod $be->delete( $schema, $id );
354 #pod
355 #pod Delete an item. C<$schema> is the schema name. C<$id> is the ID of the
356 #pod item to delete: Either a string for a single key field, or a hash
357 #pod reference for a composite key. Returns a boolean that is true if a row
358 #pod with the given ID was found and deleted. False otherwise.
359 #pod
360 #pod =cut
361  
362 0 ▶sub delete { ... }
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
363  
364 #pod =head2 delete_p
365 #pod
366 #pod my $promise = $be->delete_p( $schema, $id );
367 #pod $promise->then( sub {
368 #pod my ( $success ) = @_;
369 #pod # ...
370 #pod } );
371 #pod
372 #pod Delete an item asynchronously using promises. Returns a promise that
373 #pod resolves to a boolean indicating if the row was deleted. See L</delete>
374 #pod for arguments and return values.
375 #pod
376 #pod =cut
377  
378 0 ▶sub delete_p { ... }
Subroutine delete_p: not called CC=1 SCAR=6.9
Pod documented
379  
380 #pod =head2 query
381 #pod
382 #pod Run a raw query on the backend. Each backend may have its own arguments.
383 #pod Returns a list of hash references of data.
384 #pod
385 #pod =cut
386  
387 0 ▶sub query { ... }
Subroutine query: not called CC=1 SCAR=6.9
Pod documented
388  
389 #pod =head2 query_p
390 #pod
391 #pod Run a raw query on the backend. Each backend may have its own arguments.
392 #pod Returns a promise that resolves into a list of hash references of data.
393 #pod
394 #pod =cut
395  
396 0 ▶sub query_p { ... }
Subroutine query_p: not called CC=1 SCAR=6.9
Pod documented
397  
398 #pod =head2 read_schema
399 #pod
400 #pod my $schema = $be->read_schema;
401 #pod my $table = $be->read_schema( $table_name );
402 #pod
403 #pod Read the schema from the database tables. Returns an OpenAPI schema
404 #pod ready to be merged into the user's configuration. Can be restricted
405 #pod to only a single table.
406 #pod
407 #pod =cut
408  
409 0 ▶sub read_schema { ... }
Subroutine read_schema: not called CC=1 SCAR=6.9
Pod documented
410  
411 #pod =head1 INTERNAL METHODS
412 #pod
413 #pod These methods are documented for use in subclasses and should not need
414 #pod to be called externally.
415 #pod
416 #pod =head2 supports
417 #pod
418 #pod Returns true if the backend supports a given feature. Returns false for now.
419 #pod In the future, features like 'json' will be detectable.
420 #pod
421 #pod =cut
422  
423 0 ▶sub supports { 0 }
Subroutine supports: not called CC=1 SCAR=6.9
Pod documented
424  
425 #pod =head2 ignore_table
426 #pod
427 #pod Returns true if the given table should be ignored when doing L</read_schema>.
428 #pod By default, backends will ignore tables used by:
429 #pod
430 #pod =over
431 #pod
432 #pod =item * L<Minion> backends (L<Minion::Backend::mysql>, L<Minion::Backend::Pg>, L<Minion::Backend::SQLite>)
433 #pod =item * L<DBIx::Class::Schema::Versioned>
434 #pod =item * Mojo DB migrations (L<Mojo::mysql::Migrations>, L<Mojo::Pg::Migrations>, L<Mojo::SQLite::Migrations>)
435 #pod =item * L<Mojo::mysql::PubSub>
436 #pod
437 #pod =back
438 #pod
439 #pod =cut
440  
441 1 our %IGNORE_TABLE = (
442 mojo_migrations => 1,
443 minion_jobs => 1,
444 minion_workers => 1,
445 minion_locks => 1,
446 minion_workers_inbox => 1,
447 minion_jobs_depends => 1,
448 mojo_pubsub_subscribe => 1,
449 mojo_pubsub_notify => 1,
450 dbix_class_schema_versions => 1,
451 );
452 0 ▶sub ignore_table {
Subroutine ignore_table: not called CC=2 SCAR=17.9
Pod documented
453 0 ▶ return $IGNORE_TABLE{ $_[1] } // 0;
Condition0%0/2
$Yancy::Backend::IGNORE_TABLE{$_[1]} // 0
l!l
00
MC/DC0%0/1
$Yancy::Backend::IGNORE_TABLE{$_[1]} // 0
$Yancy::Backend::IGNORE_TABLE{$_[1]}
Truth table0%0/2
A
A= $Yancy::Backend::IGNORE_TABLE{$_[1]}
Aresult
11
00
454 }
455  
456 #pod =head2 normalize
457 #pod
458 #pod This method normalizes data to and from the database.
459 #pod
460 #pod =cut
461  
462 0 ▶sub normalize {
Subroutine normalize: not called CC=15 SCAR=54.8
Pod documented
463 0 my ( $self, $schema_name, $data ) = @_;
464 0 ▶ return undef if !$data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
465 0 my $schema = $self->schema->{ $schema_name };
466 0 ▶ my $real_schema_name = ( $schema->{'x-view'} || {} )->{schema} // $schema_name;
Condition0%0/5
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
l!l&&r!l&&!r
000
$schema->{'x-view'} || {}
l!l
00
MC/DC0%0/2
+($schema->{"x-view"} || {})->{"schema"} // $schema_name
$schema->{'x-view'} $schema_name
Truth table0%0/3
A // B
A= $schema->{'x-view'}B= $schema_name
ABresult
1X1
011
000
467 my %props = %{
468 0 $schema->{properties} || $self->schema->{ $real_schema_name }{properties}
469 0 ▶ };
Condition0%0/3
$schema->{'properties'} || $self->schema->{$real_schema_name}{'properties'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema->{'properties'} || $self->schema->{$real_schema_name}{'properties'}
$schema->{'properties'} $self->schema->{$real_schema_name}{'properties'}
Truth table0%0/3
A || B
A= $schema->{'properties'}B= $self->schema->{$real_schema_name}{'properties'}
ABresult
1X1
011
000
470 0 my %replace;
471 0 for my $key ( keys %$data ) {
472 0 ▶ next if !defined $data->{ $key }; # leave nulls alone
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{$key} 0 0 0
473 0 ▶ my $prop = $props{ $key } || next;
Condition0%0/2
$props{$key} || (next)
l!l
00
MC/DC0%0/1
$props{$key} || (next)
$props{$key}
Truth table0%0/2
A
A= $props{$key}
Aresult
11
00
474 0 my ( $type, $format ) = @{ $prop }{qw( type format )};
475 0 ▶ if ( is_type( $type, 'boolean' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_type($type, 'boolean')) { } 0 0 0
elsif (is_type($type, 'string') and is_format($format, 'date-time')) { } 0 0 0
476 # Boolean: true (1, "true"), false (0, "false")
477 $replace{ $key }
478 0 ▶ = $data->{ $key } && $data->{ $key } !~ /^false$/i
Branch: 1 branch
BranchTrueFalseTotal
$data->{$key} && !($data->{$key} =~ /^false$/iu) ? : 0 0 0
Condition0%0/3
$data->{$key} and not $data->{$key} =~ /^false$/iu
!ll&&!rl&&r
000
MC/DC0%0/2
$data->{$key} and not $data->{$key} =~ /^false$/iu
$data->{$key} not $data->{$key} =~ /^false$/iu
Truth table0%0/3
A and not(B)
A= $data->{$key}B= not $data->{$key} =~ /^false$/iu
ABresult
0X0
100
111
479 ? 1 : 0;
480 }
481 ▶ elsif ( is_type( $type, 'string' ) && is_format( $format, 'date-time' ) ) {
Condition0%0/3
is_type($type, "string") and is_format($format, "date-time")
!ll&&!rl&&r
000
MC/DC0%0/2
is_type($type, "string") and is_format($format, "date-time")
is_type($type, "string") is_format($format, "date-time")
Truth table0%0/3
A and B
A= is_type($type, "string")B= is_format($format, "date-time")
ABresult
0X0
100
111
482 0 ▶ if ( !$data->{ $key } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $data->{$key}) { } 0 0 0
elsif ($data->{$key} eq 'now') { } 0 0 0
483 0 $replace{ $key } = undef;
484 }
485 elsif ( $data->{ $key } eq 'now' ) {
486 0 $replace{ $key } = \'CURRENT_TIMESTAMP';
487 }
488 else {
489 0 $replace{ $key } = $data->{ $key };
490 0 $replace{ $key } =~ s/T/ /;
491 }
492 }
493 }
494  
495 0 my $params = +{ %$data, %replace };
496 0 return $params;
497 }
498  
499 #pod =head2 id_field
500 #pod
501 #pod Get the ID field for the given schema. Defaults to C<id>.
502 #pod =cut
503  
504 0 ▶sub id_field {
Subroutine id_field: not called CC=2 SCAR=17.9
Pod documented
505 0 my ( $self, $schema ) = @_;
506 0 ▶ return $self->schema->{ $schema }{ 'x-id-field' } || 'id';
Condition0%0/2
$self->schema->{$schema}{'x-id-field'} || 'id'
l!l
00
MC/DC0%0/1
$self->schema->{$schema}{'x-id-field'} || 'id'
$self->schema->{$schema}{'x-id-field'}
Truth table0%0/2
A
A= $self->schema->{$schema}{'x-id-field'}
Aresult
11
00
507 }
508  
509 #pod =head2 id_where
510 #pod
511 #pod Get the query structure for the ID field of the given schema with the
512 #pod given ID value.
513 #pod
514 #pod =cut
515  
516 0 ▶sub id_where {
Subroutine id_where: not called CC=5 SCAR=34.0
Pod documented
517 0 my ( $self, $schema_name, $id ) = @_;
518 0 my %where;
519 0 my $id_field = $self->id_field( $schema_name );
520 0 ▶ if ( ref $id_field eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $id_field eq 'ARRAY') { } 0 0 0
521 0 for my $field ( @$id_field ) {
522 0 ▶ next unless exists $id->{ $field };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $id->{$field} 0 0 0
523 0 $where{ $field } = $id->{ $field };
524 }
525 0 ▶ die "Missing composite ID parts" if @$id_field > keys %where;
Branch: 1 branch
BranchTrueFalseTotal
if @$id_field > keys %where 0 0 0
526 }
527 else {
528 0 $where{ $id_field } = $id;
529 }
530 0 return %where;
531 }
532  
533 1 1;
534  
535 __END__
« Yancy/Backend/MojoDB.pm ↑ Summary Yancy/Backend/Dbic.pm »