File Coverage

blib/lib/DBIx/Class/Schema/PopulateMore/Inflator/Find.pm
Criterion Covered Total %
statement 14 17 82.3
branch 3 6 50.0
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 20 26 76.9


line stmt bran cond sub pod time code
1             package DBIx::Class::Schema::PopulateMore::Inflator::Find;
2              
3 2     2   1449 use Moo;
  2         36  
  2         10  
4             extends 'DBIx::Class::Schema::PopulateMore::Inflator';
5              
6             =head1 NAME
7              
8             DBIx::Class::Schema::PopulateMore::Inflator::Find - Inflate via ResultSet->find
9            
10             =head1 SYNOPSIS
11              
12             !Find:Rating.10 => $schema->resultset('Rating')->find(10);
13             !Find:Rating.[key=10] => $schema->resultset('Rating')->find(10);
14              
15             =head1 DESCRIPTION
16              
17             Given a Source.$value, do a $schema->Resultset('Source')->find($value) and use
18             that value. We can't find anything, throw an exception.
19              
20             =head1 ATTRIBUTES
21              
22             This class defines the following attributes.
23              
24             =head1 METHODS
25              
26             This module defines the following methods.
27              
28             =head2 inflate($command, $string)
29              
30             This is called by Populate's dispatcher, when there is a match.
31              
32             =cut
33              
34             sub inflate
35             {
36 4     4 1 8 my ($self, $command, $string) = @_;
37 4         16 my ($source, $id) = split('\.', $string);
38              
39 4 50       31 if(my $resultset = $command->schema->resultset($source)) {
40 4 50       1440 if($id =~m/^\[.+\]$/) {
41 4         21 my ($pairs) = ($id=~m/^\[(.+)\]$/);
42 4         17 my @pairs = split(',', $pairs);
43 4         9 my %keys = map {split('=', $_) } @pairs;
  4         21  
44 4         11 $id = \%keys;
45             }
46 4 50       18 if(my $result = $resultset->find($id)) {
47 4         15020 return $result;
48             } else {
49 0           $command->exception_cb->("Can't find result for '$id' in '$source'");
50             }
51             } else {
52 0           $command->exception_cb->("Can't find resultset for $source in $string");
53             }
54 0           return;
55             }
56              
57              
58             =head1 AUTHOR
59              
60             Please see L<DBIx::Class::Schema::PopulateMore> For authorship information
61              
62             =head1 LICENSE
63              
64             Please see L<DBIx::Class::Schema::PopulateMore> For licensing terms.
65              
66             =cut
67              
68              
69             1;