line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Date: 2003/05/05 16:50:12 $ |
2
|
|
|
|
|
|
|
# $Revision: 1.4 $ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::Z3950::AsyncZ::ZSend; |
6
|
1
|
|
|
1
|
|
1535
|
use Net::Z3950; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Carp; |
8
|
|
|
|
|
|
|
use strict; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
{ |
11
|
|
|
|
|
|
|
my $mgr; |
12
|
|
|
|
|
|
|
sub getMgr { |
13
|
|
|
|
|
|
|
$mgr = new Net::Z3950::Manager(), if !$mgr; |
14
|
|
|
|
|
|
|
my $args = $_[0]->_getFieldValue('Z3950_options'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
foreach my $key (keys %$args) { |
17
|
|
|
|
|
|
|
# reset our value so it doesn't accidentally clobber the one set by $mgr |
18
|
|
|
|
|
|
|
# this applies the $mgr options to all _params objects |
19
|
|
|
|
|
|
|
$_[0]->_setFieldValue($key=>$args->{$key}); |
20
|
|
|
|
|
|
|
$mgr->option($key=>$args->{$key}); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $mgr; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub connection { return $_[0]->{_conn}; } |
28
|
|
|
|
|
|
|
sub rs { return $_[0]->{_rs}; } |
29
|
|
|
|
|
|
|
sub rsize { return $_[0]->{_rsize}; } |
30
|
|
|
|
|
|
|
sub querytype { return $_[0]->{_conn}->option('querytype'); } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub closedown { |
33
|
|
|
|
|
|
|
$_[0]->{_conn}->close() if $_[0]->{_open}; |
34
|
|
|
|
|
|
|
$_[0]->{_open} = 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
|
|
|
|
|
|
my ($class, %arg) = @_; |
39
|
|
|
|
|
|
|
my $self = { # _params query, if any, substituted at fork in Async |
40
|
|
|
|
|
|
|
_query => $arg{query} || croak("missing query"), |
41
|
|
|
|
|
|
|
_mgr => $arg{manager} || getMgr($arg{options}), |
42
|
|
|
|
|
|
|
_host => $arg{host}, |
43
|
|
|
|
|
|
|
_port => $arg{port}, |
44
|
|
|
|
|
|
|
_db => $arg{db}, |
45
|
|
|
|
|
|
|
_rs => "", # set in sendQuery |
46
|
|
|
|
|
|
|
_rsize => 0, # set in sendQuery |
47
|
|
|
|
|
|
|
_open => 0, # set in sendQuery |
48
|
|
|
|
|
|
|
_options => $arg{options}, |
49
|
|
|
|
|
|
|
_querytype => $arg{querytype}, # set to default (prefix) if undefined |
50
|
|
|
|
|
|
|
_preferredRecordSyntax => $arg{preferredRecordSyntax} |
51
|
|
|
|
|
|
|
|| Net::Z3950::RecordSyntax::USMARC |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
my $qt = $self->{_options}->_getFieldValue('querytype'); |
55
|
|
|
|
|
|
|
$self->{_querytype} = $qt if $qt; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $ps = $self->{_options}->_getFieldValue('preferredRecordSyntax'); |
58
|
|
|
|
|
|
|
$self->{_preferredRecordSyntax} = $ps if $ps; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
bless $self,$class; |
61
|
|
|
|
|
|
|
$self->{_conn} = $self->make_connection(); |
62
|
|
|
|
|
|
|
$self->{_open} = 1 if $self->{_conn}; |
63
|
|
|
|
|
|
|
return $self; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub sendQuery { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
$self->{_conn}->option(querytype => $self->{querytype}), if $self->{querytype}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $rs = $self->{_conn}->search($self->{_query}); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if(!$rs) { |
76
|
|
|
|
|
|
|
Net::Z3950::AsyncZ::Errors::report_error($self->{_conn}); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
$self->{_rs} = $rs; |
79
|
|
|
|
|
|
|
$self->{_rsize} = $rs->size(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub make_connection { |
85
|
|
|
|
|
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $conn = new Net::Z3950::Connection($self->{_mgr}, $self->{_host}, $self->{_port}) |
88
|
|
|
|
|
|
|
or return 0; |
89
|
|
|
|
|
|
|
$conn->option(databaseName => $self->{_db}); |
90
|
|
|
|
|
|
|
$conn->option(preferredRecordSyntax=>$self->{_preferredRecordSyntax}) |
91
|
|
|
|
|
|
|
if defined $self->{_preferredRecordSyntax}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return $conn; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |