File Coverage

blib/lib/Catmandu/Store/CA.pm
Criterion Covered Total %
statement 15 35 42.8
branch 0 6 0.0
condition n/a
subroutine 5 7 71.4
pod 1 2 50.0
total 21 50 42.0


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