File Coverage

blib/lib/OpenMuseum.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package OpenMuseum;
2              
3 1     1   23935 use 5.006;
  1         20  
  1         53  
4 1     1   12 use strict;
  1         2  
  1         42  
5 1     1   6 use warnings FATAL => 'all';
  1         5  
  1         53  
6 1     1   6 use feature ':5.10';
  1         2  
  1         136  
7 1     1   430 use YAML qw/LoadFile DumpFile/;
  0            
  0            
8             use DBI;
9              
10             =head1 NAME
11              
12             OpenMuseum - Data provider or the OpenMusem museum management
13             system.
14              
15             =head1 VERSION
16              
17             Version 0.12
18              
19             =cut
20              
21             our $VERSION = '0.12';
22              
23              
24             =head1 SYNOPSIS
25              
26             This module is designed to interact with the databases used by
27             OpenMuseum. The intent is to provide an object-oriented interface
28             to the database, abstracting away the SQL heavy lifting.
29              
30             Use:
31              
32             use OpenMuseum;
33             $om = OpenMuseum->new(-host => 'localhost', -db => 'openmuseum', -username => 'museum', -password => 'password');
34             $stat = $om->authen("username", "passwordhashhere"); #not necessarily a required step
35             $rep = $om->report("SELECT id, name, address, email_address, expiry FROM members WHERE expiry LESSTHAN '2022/15/14'" "id");
36             # dostuff with the results of the report
37            
38              
39             =head1 METHODS
40              
41             =head2 new
42              
43             The new routine returns an initialized OpenMuseum object.
44              
45             This method takes arguments as a hash constructor.
46              
47             EG:
48             $om = OpenMuseum->new(options here);
49              
50             These arguments will default, as shown here
51              
52             -username
53             museummate
54             -password
55             ImAVeryBadPassword
56             -host
57             localhost
58             -db
59             openmusem
60              
61             =cut
62              
63             sub new{
64             my $class = shift;
65             my %options = @_;
66             my $self = {};
67             bless $self, $class;
68             $options{-username} ||= 'museummate';
69             $options{-password} ||= 'ImAVeryBadPassword';
70             $options{-host} ||= 'localhost';
71             $options{-db} ||= 'openmuseum';
72             $self->{options} = %options;
73             $self->initialize();
74             return $self;
75             }
76              
77             =head2 initialize
78              
79             Shh, nothing to see here...
80              
81             This is an internal method used to parse the config file, and
82             create the database handle used to query the system.
83              
84             =cut
85              
86             sub initialize{
87             my $self = shift;
88             $self->{dbn} = $self->gendbn();
89             $self->{dbh} = DBI->connect($self->{dbn}, $self->{options}->{-username}, $self->{options}->{-password});
90             }
91              
92             =head2 gendb
93              
94             Another private method used to construct a DBN for the DBI system.
95              
96             =cut
97              
98             sub gendb{
99             my $self = shift;
100             return "DBI:mysql:".$self->{options}->{-db}.";host=".$self->{options}->{-host};
101             }
102              
103             =head2 authfiles
104              
105             This method returns an array reference being a list of different
106             entries in an authority file. it tkesone argument, the name of
107             an authority file.
108              
109             =cut
110              
111             sub authfiles{
112             my $self = shift;
113             my $file = lc(shift);
114             $statement = "SELECT id, item, other FROM authfiles WHERE filename == '$file'";
115             return $self->{dbh}->selectall_arrayref($statement);
116             }
117              
118             =head2 authen
119              
120             The authen function is used to authenticate a user, it takes two
121             parameters: user and password.
122              
123             =cut
124              
125             sub authen{
126             my $self = shift;
127             my $user = shift;
128             my $pass = shift;
129             my $query = "SELECT id FROM users WHERE name == $user AND pass == $pass";
130             my $res = $self->{dbh}->selectrow_hashref($query, "id");
131             if (defined($res)) {
132             return $res->{id};
133             } else {
134             return undef;
135             }
136             }
137              
138             =head2 options
139              
140             The options function will get and set options. It takes two options,
141             the key and the value, the value is optional and will continue to be
142             the previous value. This returns current value of the option $key.
143              
144             =cut
145              
146             sub options{
147             my $self = shift;
148             my $name = shift;
149             my $val = shift;
150             $self->{options}->{$name} = defined($val) ? $val : $self->{options}->{$name};
151             return $self->{options}->{$name};
152             }
153              
154             =head2 report
155              
156             This function performs database reports, and is very handy. It takes two
157             arguments, an SQL query and a reference column. THat is the name of a column
158             to use as the lookup. It will either return a hashreference to the results of
159             the query, or an error if the query was not a 'SELECT' query.
160              
161             =cut
162              
163             sub report{
164             my $self = shift;
165             my $report = shift;
166             my $reffield = shift;
167             if ($report =~ /^select.*/i) {
168             return $self->{dbh}->selectall_hashref($report, $reffield);
169             }else {
170             return "Bad Report, not select!";
171             }
172             }
173              
174             =head2 accessions
175              
176             This routine takes at least one argument, a command. Possible commands are
177             query, ids, retrieve, modify, and create.
178              
179             =head3 query
180              
181              
182              
183             =head3 retrieve
184              
185              
186              
187             =head3 ids
188              
189              
190              
191             =head3 modify
192              
193              
194              
195             =head3 create
196              
197              
198              
199             =cut
200              
201             sub accessions{
202             my $self = shift;
203             my $type = shift;
204             if ($type eq "query") {
205             } elsif ($type eq "ids") {
206             } elsif ($type eq "retrieve") {
207             } elsif ($type eq "modify") {
208             } elsif ($type eq "create") {
209             } else {
210            
211             }
212             }
213              
214             =head2 multimedia
215              
216             =cut
217              
218             sub multimedia{
219             my $self = shift;
220             my $type = shift;
221             if ($type eq "query") {
222             } elsif ($type eq "ids") {
223             } elsif ($type eq "retrieve") {
224             } elsif ($type eq "modify") {
225             } elsif ($type eq "create") {
226             } else {
227            
228             }
229              
230             }
231              
232             =head2 contacts
233              
234             =cut
235              
236             sub contacts{
237             my $self = shift;
238             my $type = shift;
239             if ($type eq "query") {
240             } elsif ($type eq "ids") {
241             } elsif ($type eq "retrieve") {
242             } elsif ($type eq "modify") {
243             } elsif ($type eq "create") {
244             } else {
245            
246             }
247              
248             }
249              
250             =head2 archive
251              
252             =cut
253              
254             sub archive{
255             my $self = shift;
256             my $type = shift;
257             if ($type eq "query") {
258             } elsif ($type eq "ids") {
259             } elsif ($type eq "retrieve") {
260             } elsif ($type eq "modify") {
261             } elsif ($type eq "create") {
262             } else {
263            
264             }
265              
266             }
267              
268             =head2 exhibits
269              
270             =cut
271              
272             sub exhibits{
273             my $self = shift;
274             my $type = shift;
275             if ($type eq "list") {
276             } elsif ($type eq "create") {
277             } elsif ($type eq "suspend") {
278             } elsif ($type eq "display") {
279             } elsif ($type eq "edit") {
280             } else {
281            
282             }
283             }
284              
285             =head2 objects
286              
287             =cut
288              
289             sub objects {
290              
291             }
292              
293             =head2 campaigns
294              
295             =cut
296              
297             sub campaigns{
298              
299             }
300              
301             =head2 tcustody
302              
303             =cut
304              
305             sub tcustody{
306             #temp custody
307             }
308              
309             =head2 inloan
310              
311             =cut
312              
313             sub inloan{
314              
315             }
316              
317             =head2 outloan
318              
319             =cut
320              
321             sub outloan{
322              
323             }
324              
325             sub deaccession{
326              
327             }
328              
329             sub bios{
330              
331             }
332              
333             sub sites{
334              
335             }
336              
337             =head2 control
338              
339             =cut
340              
341             sub control{
342             my $self = shift;
343             my $type = shift;
344             }
345              
346             =head1 AUTHOR
347              
348             Samuel W. Flint, C<< >>
349              
350             =head1 BUGS
351              
352             Please report any bugs or feature requests to C, or through
353             the web interface at L. I will be notified, and then you'll
354             automatically be notified of progress on your bug as I make changes.
355              
356              
357              
358              
359             =head1 SUPPORT
360              
361             You can find documentation for this module with the perldoc command.
362              
363             perldoc OpenMuseum
364              
365              
366             You can also look for information at:
367              
368             =over 4
369              
370             =item * RT: CPAN's request tracker (report bugs here)
371              
372             L
373              
374             =item * AnnoCPAN: Annotated CPAN documentation
375              
376             L
377              
378             =item * CPAN Ratings
379              
380             L
381              
382             =item * Search CPAN
383              
384             L
385              
386             =back
387              
388              
389             =head1 ACKNOWLEDGEMENTS
390              
391              
392             =head1 LICENSE AND COPYRIGHT
393              
394             Copyright 2013 Samuel W. Flint.
395              
396             This program is free software; you can redistribute it and/or modify
397             it under the terms of the GNU General Public License as published by
398             the Free Software Foundation; version 2 dated June, 1991 or at your option
399             any later version.
400              
401             This program is distributed in the hope that it will be useful,
402             but WITHOUT ANY WARRANTY; without even the implied warranty of
403             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
404             GNU General Public License for more details.
405              
406             A copy of the GNU General Public License is available in the source tree;
407             if not, write to the Free Software Foundation, Inc.,
408             59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
409              
410              
411             =cut
412              
413             1; # End of OpenMuseum