« PONAPI/DAO/Request/Role/HasDataBulk.pm
↑ Summary
Test/PONAPI/Repository/MockDB/Table/Relationships.pm »
| 1 | # ABSTRACT: Interface role for PONAPI::DAO repositories | ||
| 2 | package PONAPI::Repository; | ||
| 3 | |||
| 4 | 8 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 8 | requires 'has_type'; | |
| 7 | 8 | requires 'has_relationship'; | |
| 8 | 8 | requires 'has_one_to_many_relationship'; | |
| 9 | 8 | requires 'type_has_fields'; | |
| 10 | |||
| 11 | 8 | requires 'retrieve'; | |
| 12 | 8 | requires 'retrieve_all'; | |
| 13 | 8 | requires 'retrieve_relationships'; | |
| 14 | 8 | requires 'retrieve_by_relationship'; | |
| 15 | 8 | requires 'create'; | |
| 16 | 8 | requires 'create_relationships'; | |
| 17 | 8 | requires 'update'; | |
| 18 | 8 | requires 'update_relationships'; | |
| 19 | 8 | requires 'delete'; | |
| 20 | 8 | requires 'delete_relationships'; | |
| 21 | |||
| 22 | 8 | ▶ | no Moose::Role; 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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.003002 | ||
| 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 | A repository is an abstracted set of collections of resources, in the | ||
| 52 | "Uniform Resource Locator" sense, which may or may not directly | ||
| 53 | reflect your data source model. Your repository class merely needs to | ||
| 54 | define sensible behaviours for the required methods defined here in | ||
| 55 | C<PONAPI::Repository> and that may be as simple as a direct reflection | ||
| 56 | of your data source model or it may allow for more useful abtractions. | ||
| 57 | Classes implementing repositories for L<PONAPI::DAO> must consume the | ||
| 58 | C<PONAPI::Repository> role; this ensures that the methods required by | ||
| 59 | the DAO to fullfil the implementation are all present. | ||
| 60 | |||
| 61 | The arguments that each method can receive are expanded on in | ||
| 62 | L<PONAPI::DAO>; some differences are explained below. Keep in mind that, | ||
| 63 | with the exceptions of the C<has_*> methods, B<all> methods | ||
| 64 | will receive a C<document> argument, which is always an instance of | ||
| 65 | C<PONAPI::Document>, but not necessarily a B<new> instance. | ||
| 66 | |||
| 67 | =head1 REQUIRES | ||
| 68 | |||
| 69 | =head2 $obj->has_type( $type ) | ||
| 70 | |||
| 71 | Must return true if the repository handles $type | ||
| 72 | |||
| 73 | =head2 $obj->has_relationship( $type1, $type2 ) | ||
| 74 | |||
| 75 | Must return true if C<$type1> has a relationship to C<$type2>. | ||
| 76 | |||
| 77 | # Do articles have comments? | ||
| 78 | $obj->has_relationship('articles', 'comments'); | ||
| 79 | |||
| 80 | =head2 $obj->has_one_to_many_relationship($type1, $type2) | ||
| 81 | |||
| 82 | Must return true if C<$type1> has a relationship to C<$type2>, and | ||
| 83 | that relationship is one-to-many. | ||
| 84 | |||
| 85 | =head2 retrieve | ||
| 86 | |||
| 87 | =head2 retrieve_all | ||
| 88 | |||
| 89 | =head2 retrieve_relationships | ||
| 90 | |||
| 91 | =head2 retrieve_by_relationship | ||
| 92 | |||
| 93 | =head2 create | ||
| 94 | |||
| 95 | =head2 update | ||
| 96 | |||
| 97 | Return value MUST be one of the C<PONAPI_UPDATE_*> constants provided by | ||
| 98 | C<PONAPI::Constants>, like C<PONAPI_UPDATED_EXTENDED>. | ||
| 99 | |||
| 100 | If the update operation updated more than what was requested (for example, | ||
| 101 | an C<updated> column in the table, and that column is part of the resource), | ||
| 102 | then it must return C<PONAPI_UPDATED_EXTENDED>; if the update on the primary | ||
| 103 | resource did nothing, then it must return C<PONAPI_UPDATED_NOTHING>. | ||
| 104 | In all other non-error situations, it must return C<PONAPI_UPDATED_NORMAL> | ||
| 105 | instead. | ||
| 106 | |||
| 107 | =head2 delete | ||
| 108 | |||
| 109 | =head2 create_relationships | ||
| 110 | |||
| 111 | See L</update>. | ||
| 112 | |||
| 113 | C<data> will be an arrayref of resources. | ||
| 114 | |||
| 115 | =head2 update_relationships | ||
| 116 | |||
| 117 | See L</update>. | ||
| 118 | |||
| 119 | C<data> will be either undef, a hashref, or an arrayref, depending on | ||
| 120 | what sort of relationship the request is trying to update. | ||
| 121 | |||
| 122 | =head2 delete_relationships | ||
| 123 | |||
| 124 | See L</update>. | ||
| 125 | |||
| 126 | C<data> will be an arrayref of resources. | ||
| 127 | |||
| 128 | =head1 AUTHORS | ||
| 129 | |||
| 130 | =over 4 | ||
| 131 | |||
| 132 | =item * | ||
| 133 | |||
| 134 | Mickey Nasriachi <mickey@cpan.org> | ||
| 135 | |||
| 136 | =item * | ||
| 137 | |||
| 138 | Stevan Little <stevan@cpan.org> | ||
| 139 | |||
| 140 | =item * | ||
| 141 | |||
| 142 | Brian Fraser <hugmeir@cpan.org> | ||
| 143 | |||
| 144 | =back | ||
| 145 | |||
| 146 | =head1 COPYRIGHT AND LICENSE | ||
| 147 | |||
| 148 | This software is copyright (c) 2017 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||
| 149 | |||
| 150 | This is free software; you can redistribute it and/or modify it under | ||
| 151 | the same terms as the Perl 5 programming language system itself. | ||
| 152 | |||
| 153 | =cut | ||