| 1 | # ABSTRACT: DAO request role - `include` | ||||||||||
| 2 | package PONAPI::DAO::Request::Role::HasInclude; | ||||||||||
| 3 | |||||||||||
| 4 | 8 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | has include => ( | ||||||||||
| 7 | traits => [ 'Array' ], | ||||||||||
| 8 | is => 'ro', | ||||||||||
| 9 | isa => 'ArrayRef', | ||||||||||
| 10 | 82 | ▶ | default => sub { +[] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | handles => { | |||||||||
| 12 | "has_include" => 'count', | ||||||||||
| 13 | }, | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | sub _validate_include { | ||||||||||
| 17 | 97 | ▶ | my ( $self, $args ) = @_; | ||||||||
|
Subroutine
_validate_include: called CC=5 SCAR=16.1
| |||||||||||
| 18 | |||||||||||
| 19 | 97 | ▶ | return unless defined $args->{include}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 20 | ▶ | return $self->_bad_request( "`include` is missing values" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | unless $self->has_include >= 1; | ||||||||||
| 23 | |||||||||||
| 24 | 19 | my $type = $self->type; | |||||||||
| 25 | |||||||||||
| 26 | 19 | for ( @{ $self->include } ) { | |||||||||
| 27 | 24 | ▶ | $self->repository->has_relationship( $type, $_ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | or $self->_bad_request( "Types `$type` and `$_` are not related", 404 ); | ||||||||||
| 29 | } | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 8 | ▶ | no Moose::Role; 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | __END__ | ||||||||||
| 35 | |||||||||||
| 36 | =pod | ||||||||||
| 37 | |||||||||||
| 38 | =encoding UTF-8 | ||||||||||
| 39 | |||||||||||
| 40 | =head1 NAME | ||||||||||
| 41 | |||||||||||
| 42 | PONAPI::DAO::Request::Role::HasInclude - DAO request role - `include` | ||||||||||
| 43 | |||||||||||
| 44 | =head1 VERSION | ||||||||||
| 45 | |||||||||||
| 46 | version 0.003002 | ||||||||||
| 47 | |||||||||||
| 48 | =head1 AUTHORS | ||||||||||
| 49 | |||||||||||
| 50 | =over 4 | ||||||||||
| 51 | |||||||||||
| 52 | =item * | ||||||||||
| 53 | |||||||||||
| 54 | Mickey Nasriachi <mickey@cpan.org> | ||||||||||
| 55 | |||||||||||
| 56 | =item * | ||||||||||
| 57 | |||||||||||
| 58 | Stevan Little <stevan@cpan.org> | ||||||||||
| 59 | |||||||||||
| 60 | =item * | ||||||||||
| 61 | |||||||||||
| 62 | Brian Fraser <hugmeir@cpan.org> | ||||||||||
| 63 | |||||||||||
| 64 | =back | ||||||||||
| 65 | |||||||||||
| 66 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 67 | |||||||||||
| 68 | This software is copyright (c) 2017 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||||||||||
| 69 | |||||||||||
| 70 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 71 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 72 | |||||||||||
| 73 | =cut | ||||||||||