| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Catmandu::Store::CA; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 597 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 4 | 1 |  |  | 1 |  | 3 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 3 | use Moo; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 7 | 1 |  |  | 1 |  | 216 | use Catmandu::Sane; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 193 | use Catmandu::Store::CA::Bag; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 406 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | with 'Catmandu::Store'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has url         => (is => 'ro', required => 1); | 
| 14 |  |  |  |  |  |  | has username    => (is => 'ro', required => 1); | 
| 15 |  |  |  |  |  |  | has password    => (is => 'ro', required => 1); | 
| 16 |  |  |  |  |  |  | has model       => (is => 'ro', default => 'ca_objects'); | 
| 17 |  |  |  |  |  |  | has lang        => (is => 'ro', default => 'nl_NL'); | 
| 18 |  |  |  |  |  |  | has _field_list => (is => 'rw', default => sub { return []; }); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub BUILDARGS { | 
| 21 | 0 |  |  | 0 | 0 |  | my ($class, %args) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 0 |  |  |  |  |  | my $field_list = delete $args{'field_list'}; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 | 0 |  |  |  |  | if ($field_list) { | 
| 26 | 0 |  |  |  |  |  | my @list = split(/,/, $field_list); | 
| 27 | 0 |  |  |  |  |  | my @fields = map { $_ =~ s/^\s+//; $_; } @list; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 28 | 0 |  |  |  |  |  | $args{'_field_list'} = \@fields; | 
| 29 |  |  |  |  |  |  | } | 
| 30 | 0 |  |  |  |  |  | return \%args; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub field_list { | 
| 34 | 0 |  |  | 0 | 1 |  | my ($self, $field_list) = @_; | 
| 35 | 0 | 0 |  |  |  |  | if ($field_list) { | 
| 36 | 0 |  |  |  |  |  | my @list = split(/,/, $field_list); | 
| 37 | 0 |  |  |  |  |  | my @fields = map { $_ =~ s/^\s+//; $_; } @list; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  |  | $self->_field_list = \@fields; | 
| 39 |  |  |  |  |  |  | } else { | 
| 40 | 0 |  |  |  |  |  | return join(',', @{$self->_field_list}); | 
|  | 0 |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | 1; | 
| 45 |  |  |  |  |  |  | __END__ | 
| 46 |  |  |  |  |  |  | =encoding utf-8 | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head1 NAME | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | Catmandu::Store::CA - Retrieve items from a L<CollectiveAccess|http://collectiveaccess.org/> instance | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # From the command line | 
| 55 |  |  |  |  |  |  | catmandu export CA to YAML --id 1234 --username demo --password demo --url http://demo.collectiveaccess.org --model ca_objects --lang nl_NL --field_list 'ca_entities, preferred_labels' | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | # From a Catmandu Fix | 
| 58 |  |  |  |  |  |  | lookup_in_store( | 
| 59 |  |  |  |  |  |  | object_id, | 
| 60 |  |  |  |  |  |  | CA, | 
| 61 |  |  |  |  |  |  | url: http://demo.collectiveaccess.org, | 
| 62 |  |  |  |  |  |  | username: demo, | 
| 63 |  |  |  |  |  |  | password: demo, | 
| 64 |  |  |  |  |  |  | model: ca_objects, | 
| 65 |  |  |  |  |  |  | lang: nl_NL, | 
| 66 |  |  |  |  |  |  | field_list: 'ca_entities, preferred_labels' | 
| 67 |  |  |  |  |  |  | ) | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # From Perl code | 
| 70 |  |  |  |  |  |  | use Catmandu; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | my $store = Catmandu->store('CA', | 
| 73 |  |  |  |  |  |  | username   => 'demo', | 
| 74 |  |  |  |  |  |  | password   => 'demo', | 
| 75 |  |  |  |  |  |  | url        => 'http://demo.collectiveaccess.org', | 
| 76 |  |  |  |  |  |  | model      => 'ca_objects', | 
| 77 |  |  |  |  |  |  | lang       => 'nl_NL', | 
| 78 |  |  |  |  |  |  | field_list => 'ca_entities, preferred_labels' | 
| 79 |  |  |  |  |  |  | )->bag; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | my $item = $store->get('1234'); | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | A Catmandu::Store::CA is Perl package that can query a L<CollectiveAccess|http://collectiveaccess.org> instance. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 url | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | C<url> of the CA instance (e.g. I<http://demo.collectiveaccess.org>). | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 username | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Name of a user that can be used to query the API. If you want to store | 
| 98 |  |  |  |  |  |  | items in the CA instance, it must have the necessary rights. | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head2 password | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | Password for the user. | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head2 model | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | The API can access several tables from the CA instance, called I<model> in this module. | 
| 107 |  |  |  |  |  |  | The model is by default C<ca_objects>, but the following are also supported: | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =over | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =item C<ca_objects> | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =item C<ca_object_lots> | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =item C<ca_entities> | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =item C<ca_places> | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =item C<ca_occurrences> | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =item C<ca_collections> | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =item C<ca_storage_locations> | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =item C<ca_loans> | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =item C<ca_movements> | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =back | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =head2 lang | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | The language (locale) in which to return the data. Set to C<nl_NL> by default, | 
| 134 |  |  |  |  |  |  | will automatically fall back to C<en_US> if the attribute does not exist in the | 
| 135 |  |  |  |  |  |  | selected locale. Use the L<IETF language tag|https://en.wikipedia.org/wiki/IETF_language_tag>. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head2 field_list | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | A comma-separated, quoted, (C<'foo, bar'>) list of fields that the CollectiveAccess | 
| 140 |  |  |  |  |  |  | API should return. Is optional and can be left empty to return the default 'summary'. | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =head1 METHODS | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | =head2 new(%configuration) | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | Create a new Catmandu::Store::CA | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =head2 get($id) | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | Retrieve a CA record given an identifier. This returns whatever | 
| 151 |  |  |  |  |  |  | the CA administrator designated as the "summary" of the record. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =head2 add($data) | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | Create a new CA record. See L<here|http://docs.collectiveaccess.org/wiki/Web_Service_API#Creating_new_records> to | 
| 156 |  |  |  |  |  |  | see what data you must provide to create a record. | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =head2 update($id, $data) | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | Update a new CA record. See L<here|http://docs.collectiveaccess.org/wiki/Web_Service_API#Creating_new_records> to | 
| 161 |  |  |  |  |  |  | see what data you must provide to create a record. | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head2 delete($id) | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | Delete (I<soft delete>) a record. | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head2 each() | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | Not supported | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =head1 AUTHOR | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | Pieter De Praetere E<lt>pieter at packed.beE<gt> | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | Copyright 2017- PACKED vzw | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head1 LICENSE | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | This library is free software; you can redistribute it and/or modify | 
| 182 |  |  |  |  |  |  | it under the same terms as Perl itself. | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | L<Catmandu> | 
| 187 |  |  |  |  |  |  | L<Catmandu::Store::VKC> | 
| 188 |  |  |  |  |  |  | L<Catmandu::CA::API> | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =cut |