File Coverage

blib/lib/PONAPI/DAO/Request/DeleteRelationships.pm
Criterion Covered Total %
statement 19 19 100.0
branch 7 10 70.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 31 36 86.1


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