File Coverage

blib/lib/PONAPI/DAO/Request/Role/HasInclude.pm
Criterion Covered Total %
statement 13 13 100.0
branch 6 6 100.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: DAO request role - `include`
2             package PONAPI::DAO::Request::Role::HasInclude;
3              
4 8     8   4161 use Moose::Role;
  8         23  
  8         53  
5              
6             has include => (
7             traits => [ 'Array' ],
8             is => 'ro',
9             isa => 'ArrayRef',
10             default => sub { +[] },
11             handles => {
12             "has_include" => 'count',
13             },
14             );
15              
16             sub _validate_include {
17 97     97   226 my ( $self, $args ) = @_;
18              
19 97 100       356 return unless defined $args->{include};
20              
21 20 100       894 return $self->_bad_request( "`include` is missing values" )
22             unless $self->has_include >= 1;
23              
24 19         649 my $type = $self->type;
25              
26 19         61 for ( @{ $self->include } ) {
  19         618  
27 24 100       660 $self->repository->has_relationship( $type, $_ )
28             or $self->_bad_request( "Types `$type` and `$_` are not related", 404 );
29             }
30             }
31              
32 8     8   41125 no Moose::Role; 1;
  8         24  
  8         38  
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.003003
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) 2019 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