File Coverage

blib/lib/PONAPI/DAO/Request/CreateRelationships.pm
Criterion Covered Total %
statement 19 19 100.0
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 32 36 88.8


line stmt bran cond sub pod time code
1             # ABSTRACT: DAO request - create relationships
2             package PONAPI::DAO::Request::CreateRelationships;
3              
4 8     8   64 use Moose;
  8         21  
  8         65  
5              
6             extends 'PONAPI::DAO::Request';
7              
8             with 'PONAPI::DAO::Request::Role::UpdateLike',
9             'PONAPI::DAO::Request::Role::HasDataBulk',
10             'PONAPI::DAO::Request::Role::HasDataMethods',
11             'PONAPI::DAO::Request::Role::HasID',
12             'PONAPI::DAO::Request::Role::HasRelationshipType';
13              
14 14     14 0 112 sub check_data_type_match { 1 } # to avoid code duplications in HasDataMethods
15              
16             sub execute {
17 18     18 0 40 my $self = shift;
18              
19 18 100       506 if ( $self->is_valid ) {
20 9         250 my @ret = $self->repository->create_relationships( %{ $self } );
  9         2259  
21 4 50       880 $self->_add_success_meta(@ret)
22             if $self->_verify_update_response(@ret);
23             }
24              
25 12         233 return $self->response();
26             }
27              
28             sub _validate_rel_type {
29 17     17   58 my ( $self, $args ) = @_;
30              
31 17 100       706 return $self->_bad_request( "`relationship type` is missing for this request" )
32             unless $self->has_rel_type;
33              
34 15         411 my $type = $self->type;
35 15         516 my $rel_type = $self->rel_type;
36              
37 15 50       407 return $self->_bad_request( "Types `$type` and `$rel_type` are not related", 404 )
38             unless $self->repository->has_relationship( $type, $rel_type );
39              
40 15 100       402 return $self->_bad_request( "Types `$type` and `$rel_type` are one-to-one" )
41             unless $self->repository->has_one_to_many_relationship( $type, $rel_type );
42             }
43              
44              
45             __PACKAGE__->meta->make_immutable;
46 8     8   57022 no Moose; 1;
  8         26  
  8         48  
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             PONAPI::DAO::Request::CreateRelationships - DAO request - create relationships
57              
58             =head1 VERSION
59              
60             version 0.003003
61              
62             =head1 AUTHORS
63              
64             =over 4
65              
66             =item *
67              
68             Mickey Nasriachi <mickey@cpan.org>
69              
70             =item *
71              
72             Stevan Little <stevan@cpan.org>
73              
74             =item *
75              
76             Brian Fraser <hugmeir@cpan.org>
77              
78             =back
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This software is copyright (c) 2019 by Mickey Nasriachi, Stevan Little, Brian Fraser.
83              
84             This is free software; you can redistribute it and/or modify it under
85             the same terms as the Perl 5 programming language system itself.
86              
87             =cut