| 1 | # ABSTRACT: DAO request - create relationships | ||||||||||
| 2 | package PONAPI::DAO::Request::CreateRelationships; | ||||||||||
| 3 | |||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | extends 'PONAPI::DAO::Request'; | |||||||||
| 7 | |||||||||||
| 8 | 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 | ▶ | sub check_data_type_match { 1 } # to avoid code duplications in HasDataMethods | ||||||||
|
Subroutine
check_data_type_match: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | sub execute { | ||||||||||
| 17 | 18 | ▶ | my $self = shift; | ||||||||
|
Subroutine
execute: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | 18 | ▶ | if ( $self->is_valid ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 9 | my @ret = $self->repository->create_relationships( %{ $self } ); | |||||||||
| 21 | 4 | ▶ | $self->_add_success_meta(@ret) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | if $self->_verify_update_response(@ret); | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 12 | return $self->response(); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub _validate_rel_type { | ||||||||||
| 29 | 17 | ▶ | my ( $self, $args ) = @_; | ||||||||
|
Subroutine
_validate_rel_type: called CC=4 SCAR=13.9
| |||||||||||
| 30 | |||||||||||
| 31 | 17 | ▶ | return $self->_bad_request( "`relationship type` is missing for this request" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | unless $self->has_rel_type; | ||||||||||
| 33 | |||||||||||
| 34 | 15 | my $type = $self->type; | |||||||||
| 35 | 15 | my $rel_type = $self->rel_type; | |||||||||
| 36 | |||||||||||
| 37 | 15 | ▶ | return $self->_bad_request( "Types `$type` and `$rel_type` are not related", 404 ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | unless $self->repository->has_relationship( $type, $rel_type ); | ||||||||||
| 39 | |||||||||||
| 40 | 15 | ▶ | return $self->_bad_request( "Types `$type` and `$rel_type` are one-to-one" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | unless $self->repository->has_one_to_many_relationship( $type, $rel_type ); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||
| 46 | 8 | ▶ | no Moose; 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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.003002 | ||||||||||
| 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) 2017 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 | ||||||||||