File Coverage

blib/lib/PONAPI/Repository.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Interface role for PONAPI::DAO repositories
2             package PONAPI::Repository;
3              
4 8     8   6259 use Moose::Role;
  8         27  
  8         81  
5              
6             requires 'has_type';
7             requires 'has_relationship';
8             requires 'has_one_to_many_relationship';
9             requires 'type_has_fields';
10              
11             requires 'retrieve';
12             requires 'retrieve_all';
13             requires 'retrieve_relationships';
14             requires 'retrieve_by_relationship';
15             requires 'create';
16             requires 'create_relationships';
17             requires 'update';
18             requires 'update_relationships';
19             requires 'delete';
20             requires 'delete_relationships';
21              
22 8     8   28856 no Moose::Role; 1;
  8         21  
  8         46  
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             PONAPI::Repository - Interface role for PONAPI::DAO repositories
33              
34             =head1 VERSION
35              
36             version 0.002006
37              
38             =head1 SYNOPSIS
39              
40             package My::PONAPI::Repository {
41             use Moose;
42             with 'PONAPI::Repository';
43              
44             sub has_type { ... }
45              
46             ...
47             }
48              
49             =head1 DESCRIPTION
50              
51             Clases implementing repositories for L<PONAPI::DAO> must consume
52             the C<PONAPI::Repository> role; this ensures that the methods
53             required by the DAO to fullfil the implementation are all present.
54              
55             The arguments that each method can receive are expanded on in
56             L<PONAPI::DAO>; some differences are explained below. Keep in mind that,
57             with the exceptions of the C<has_*> methods, B<all> methods
58             will receive a C<document> argument, which is always an instance of
59             C<PONAPI::Builder::Document>, but not necessarily a B<new> instance.
60              
61             =head1 REQUIRES
62              
63             =head2 $obj->has_type( $type )
64              
65             Must return true if the repository handles $type
66              
67             =head2 $obj->has_relationship( $type1, $type2 )
68              
69             Must return true if C<$type1> has a relationship to C<$type2>.
70              
71             # Do articles have comments?
72             $obj->has_relationship('articles', 'comments');
73              
74             =head2 $obj->has_one_to_many_relationship($type1, $type2)
75              
76             Must return true if C<$type1> has a relationship to C<$type2>, and
77             that relationship is one-to-many.
78              
79             =head2 retrieve
80              
81             =head2 retrieve_all
82              
83             =head2 retrieve_relationships
84              
85             =head2 retrieve_by_relationship
86              
87             =head2 create
88              
89             =head2 update
90              
91             Return value MUST be one of the C<PONAPI_UPDATE_*> constants provided by
92             C<PONAPI::Constants>, like C<PONAPI_UPDATED_EXTENDED>.
93              
94             If the update operation updated more than what was requested (for example,
95             an C<updated> column in the table, and that column is part of the resource),
96             then it must return C<PONAPI_UPDATED_EXTENDED>; if the update on the primary
97             resource did nothing, then it must return C<PONAPI_UPDATED_NOTHING>.
98             In all other non-error situations, it must return C<PONAPI_UPDATED_NORMAL>
99             instead.
100              
101             =head2 delete
102              
103             =head2 create_relationships
104              
105             See L</update>.
106              
107             C<data> will be an arrayref of resources.
108              
109             =head2 update_relationships
110              
111             See L</update>.
112              
113             C<data> will be either undef, a hashref, or an arrayref, depending on
114             what sort of relationship the request is trying to update.
115              
116             =head2 delete_relationships
117              
118             See L</update>.
119              
120             C<data> will be an arrayref of resources.
121              
122             =end
123              
124             =head1 AUTHORS
125              
126             =over 4
127              
128             =item *
129              
130             Mickey Nasriachi <mickey@cpan.org>
131              
132             =item *
133              
134             Stevan Little <stevan@cpan.org>
135              
136             =item *
137              
138             Brian Fraser <hugmeir@cpan.org>
139              
140             =back
141              
142             =head1 COPYRIGHT AND LICENSE
143              
144             This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser.
145              
146             This is free software; you can redistribute it and/or modify it under
147             the same terms as the Perl 5 programming language system itself.
148              
149             =cut