File Coverage

blib/lib/PONAPI/DAO/Request/Create.pm
Criterion Covered Total %
statement 19 19 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 3 3 100.0
pod 0 1 0.0
total 26 30 86.6


line stmt bran cond sub pod time code
1             # ABSTRACT: DAO request - create
2             package PONAPI::DAO::Request::Create;
3              
4 8     8   67 use Moose;
  8         21  
  8         72  
5              
6             extends 'PONAPI::DAO::Request';
7              
8             with 'PONAPI::DAO::Request::Role::HasData',
9             'PONAPI::DAO::Request::Role::HasDataMethods';
10              
11             sub execute {
12 27     27 0 62 my $self = shift;
13 27         719 my $doc = $self->document;
14              
15 27         53 my @headers;
16 27 100       733 if ( $self->is_valid ) {
17 9         256 $self->repository->create( %{ $self } );
  9         113  
18 4         1040 $doc->add_meta(
19             detail => "successfully created the resource: "
20             . $self->type
21             . " => "
22             . $self->json->encode( $self->data )
23             );
24              
25 4 50       416 $doc->set_status(201) unless $doc->has_status;
26              
27 4         279 my $document = $doc->build;
28 4         5018 my $self_link = $document->{data}{links}{self};
29 4   33     50 $self_link //= "/$document->{data}{type}/$document->{data}{id}";
30              
31 4         24 push @headers, Location => $self_link;
32             }
33              
34 22         134 return $self->response( @headers );
35             }
36              
37             __PACKAGE__->meta->make_immutable;
38 8     8   56972 no Moose; 1;
  8         25  
  8         56  
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             PONAPI::DAO::Request::Create - DAO request - create
49              
50             =head1 VERSION
51              
52             version 0.003003
53              
54             =head1 AUTHORS
55              
56             =over 4
57              
58             =item *
59              
60             Mickey Nasriachi <mickey@cpan.org>
61              
62             =item *
63              
64             Stevan Little <stevan@cpan.org>
65              
66             =item *
67              
68             Brian Fraser <hugmeir@cpan.org>
69              
70             =back
71              
72             =head1 COPYRIGHT AND LICENSE
73              
74             This software is copyright (c) 2019 by Mickey Nasriachi, Stevan Little, Brian Fraser.
75              
76             This is free software; you can redistribute it and/or modify it under
77             the same terms as the Perl 5 programming language system itself.
78              
79             =cut