Net/Z3950/UDDI/Database.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 55 CC 3 SCAR 16.1
CC
3
Cov
0%
new
12.0
session
2.0
dbname
2.0
CRAP 5.0
1 package Net::Z3950::UDDI::Database;
2 use strict;
3 use warnings;
4  
5 =head1 NAME
6  
7 Net::Z3950::UDDI::Database - back-end independent database for z2uddi
8  
9 =head1 SYNOPSIS
10  
11 $db = new Net::Z3950::UDDI::Database($dbconfig);
12 $map = $db->config()->property("indexmap");
13 $rs = $db->search($rpn);
14  
15 =head1 DESCRIPTION
16  
17 C<Net::Z3950::UDDI::Database> objects represent a connection to
18 backend database of some kind or another, but hide the details of
19 whether that database is a SOAP service or a UDDI repostory (or
20 something else again) by presenting a simple, generic API.
21  
22 =head1 METHODS
23  
24 =head2 new()
25  
26 $session = new Net::Z3950::UDDI::Database($dbname, $config)
27  
28 Creates and returns a new session object for the specied user, using
29 the specified password. These authentication credentials are optional
30 if not required by the back-ends accessed by subsequent searches.
31  
32 The returned object will not be of the C<Database> base-class, but of
33 one of the subclasses such as C<Database::soap> or C<Database::uddi>.
34 This selection is made on the basis of the C<type> parameter specified
35 in the database's C<$config>: a module corresponding to that type is
36 loaded and invoked.
37  
38 =cut
39  
40 sub new {
41 my $class = shift();
42 my($session, $dbname, $config) = @_;
43  
44 my $type = $config->property("type")
45 or $session->_throw(1, "no 'type' specified for database '$dbname'");
46  
47 eval {
48 require "Net/Z3950/UDDI/plugins/$type.pm";
49 }; if ($@ && !ref $@ && $@ =~ /^Can.t locate /) {
50 $session->_throw(1,
51 "no implementation for database type '$type' (db '$dbname')");
52 } elsif ($@) {
53 die $@;
54 }
55  
56 my $this = bless {
57 session => $session,
58 dbname => $dbname,
59 config => $config,
60 }, $class;
61  
62 "Net::Z3950::UDDI::Database::$type"->rebless($this);
63 return $this;
64 }
65  
66  
67 ### Document these
68  
69 sub session { shift()->{session} }
70 sub dbname { shift()->{dbname} }
71 sub config { shift()->{config} }
72  
73  
74 # Delegate
75 sub _throw {
76 my $this = shift();
77 return $this->session()->_throw(@_);
78 }
79  
80  
81 =head2 search()
82  
83 $rs = $db->search($rpn);
84  
85 Searches the specified database using the query C<$rpn>, which is a
86 structure representing a Z39.50 Type-1 query, of the kind passed into
87 search callback functions by Index Data's SimpleServer. (That's
88 convenient!)
89  
90 Returns a result-set, and object of a subclass of
91 C<Net::Z3950::UDDI::ResultSet> corresponding to C<$db>'s particular
92 subclass of C<Net::Z3950::UDDI::Database>
93  
94 =cut
95  
96 # Of course, search() is not implemented in this class at all, but
97 # only by the subclasses.
98  
99  
100 =head1 SUBCLASSING
101  
102 I<###> to be written
103  
104 =head1 SEE ALSO
105  
106 C<Net::Z3950::UDDI::Session>
107 is the module that immediately uses this, as it maintains a mapping of
108 Z39.50 database-names to C<Database> objects.
109  
110 =head1 AUTHOR, COPYRIGHT AND LICENSE
111  
112 As for C<Net::Z3950::UDDI>.
113  
114 =cut
115  
116 1;