| 1 | package DBIx::Class::Schema::PopulateMore::Inflator::Find; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | 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 | ▶ | my ($self, $command, $string) = @_; | ||||||||
|
Subroutine
inflate: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||
| 37 | 4 | my ($source, $id) = split('\.', $string); | |||||||||
| 38 | |||||||||||
| 39 | 4 | ▶ | if(my $resultset = $command->schema->resultset($source)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 4 | ▶ | if($id =~m/^\[.+\]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 4 | my ($pairs) = ($id=~m/^\[(.+)\]$/); | |||||||||
| 42 | 4 | my @pairs = split(',', $pairs); | |||||||||
| 43 | 4 | my %keys = map {split('=', $_) } @pairs; | |||||||||
| 44 | 4 | $id = \%keys; | |||||||||
| 45 | } | ||||||||||
| 46 | 4 | ▶ | if(my $result = $resultset->find($id)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 4 | 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 | 2 | 1; | |||||||||