| 1 | package Net::Z3950::UDDI::Session; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use Data::Dumper; | ||
| 6 | $Data::Dumper::Indent = 1; | ||
| 7 | |||
| 8 | use Net::Z3950::UDDI::Database; | ||
| 9 | |||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Net::Z3950::UDDI::Session - client session for z2uddi | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | use Net::Z3950::UDDI::Session; | ||
| 18 | $session = new Net::Z3950::UDDI::Session($uddi, $user, $password); | ||
| 19 | $nhits = $session->search($config, $dbname, $rpn); | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | C<Net::Z3950::UDDI::Session> objects represent the state of a single | ||
| 24 | client session, i.e. a Z39.50 connection to the gateway. They are | ||
| 25 | created when the client's Init request is received, and updated by | ||
| 26 | subsequent client requests and back-end responses. | ||
| 27 | |||
| 28 | =head1 METHODS | ||
| 29 | |||
| 30 | =head2 new() | ||
| 31 | |||
| 32 | $session = new Net::Z3950::UDDI::Session($uddi, $user, $password); | ||
| 33 | |||
| 34 | Creates and returns a new session object for the specied user, using | ||
| 35 | the specified password, on behalf of the specified UDDI object. The | ||
| 36 | authentication credentials are optional if not required by the | ||
| 37 | back-ends accessed by subsequent searches. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub new { | ||
| 42 | my $class = shift(); | ||
| 43 | my($uddi, $user, $pass) = @_; | ||
| 44 | |||
| 45 | return bless { | ||
| 46 | uddi => $uddi, | ||
| 47 | connections => {}, # Maps dbname to back-end connection | ||
| 48 | resultsets => {}, # Maps result-set name to result-set | ||
| 49 | user => $user, | ||
| 50 | pass => $pass, | ||
| 51 | }, $class; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | =head2 search() | ||
| 56 | |||
| 57 | $rs = $session->search($dbname, $config, $setname, $rpn); | ||
| 58 | |||
| 59 | Performs a search in database named C<$dbname> in the session | ||
| 60 | C<$session>, reusing an existing database connection if one has | ||
| 61 | already been created for this session, and creating and caching a new | ||
| 62 | one otherwise. In the latter case, C<$config> is used to determine | ||
| 63 | the type of back-end database to create, among other things. The | ||
| 64 | search is for the query specified by the SimpleServer-like RPN | ||
| 65 | structure C<$rpn>. | ||
| 66 | |||
| 67 | Returns a new C<Net::Z3950::ResultSet> object. Well, actually an | ||
| 68 | object of one of the back-end-specific subclasses of that class, but | ||
| 69 | the invoker should not worry about that. The result is cached under | ||
| 70 | the specified C<$setname> and can subsequently be retrieved using | ||
| 71 | C<resultset_by_name()>. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub search { | ||
| 76 | my $this = shift(); | ||
| 77 | my($dbname, $config, $setname, $rpn) = @_; | ||
| 78 | |||
| 79 | my $db = $this->database_by_name($dbname, $config); | ||
| 80 | my $rs = $db->search($rpn); | ||
| 81 | $this->{resultsets}->{$setname} = $rs; | ||
| 82 | return $rs; | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | sub database_by_name { | ||
| 87 | my $this = shift(); | ||
| 88 | my($dbname, $config) = @_; | ||
| 89 | |||
| 90 | # Reuse connection objects that have already been made. | ||
| 91 | my $db = $this->{connections}->{$dbname}; | ||
| 92 | if (defined $db) { | ||
| 93 | # assert(deep_eq($config, $db->config()); | ||
| 94 | return $db; | ||
| 95 | } | ||
| 96 | |||
| 97 | my $dbconfig = $config->{contents}->{databases}->{$dbname} | ||
| 98 | or $this->_throw(235, $dbname); | ||
| 99 | |||
| 100 | $db = new Net::Z3950::UDDI::Database($this, $dbname, $dbconfig); | ||
| 101 | $this->{connections}->{$dbname} = $db; | ||
| 102 | return $db; | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | =head2 resultset_by_name() | ||
| 107 | |||
| 108 | $rs = $session->resultset_by_name($setname); | ||
| 109 | |||
| 110 | Returns the previously generated result-set with the specified name, | ||
| 111 | or an undefined value if no such result-set exists. | ||
| 112 | |||
| 113 | =cut | ||
| 114 | |||
| 115 | sub resultset_by_name { | ||
| 116 | my $this = shift(); | ||
| 117 | my($setname) = @_; | ||
| 118 | |||
| 119 | return $this->{resultsets}->{$setname}; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | # Delegate | ||
| 124 | sub _throw { | ||
| 125 | my $this = shift(); | ||
| 126 | return $this->{uddi}->_throw(@_); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | =head1 SEE ALSO | ||
| 131 | |||
| 132 | C<Net::Z3950::UDDI> | ||
| 133 | is the module that uses this. | ||
| 134 | |||
| 135 | C<z2uddi> is the gateway program that uses C<Net::Z3950::UDDI>. | ||
| 136 | |||
| 137 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||
| 138 | |||
| 139 | As for C<Net::Z3950::UDDI>. | ||
| 140 | |||
| 141 | =cut | ||
| 142 | |||
| 143 | 1; |