| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Date: 2003/05/06 00:35:20 $ |
|
2
|
|
|
|
|
|
|
# $Revision: 1.3 $ |
|
3
|
|
|
|
|
|
|
package Net::Z3950::AsyncZ::Options::_params; |
|
4
|
2
|
|
|
2
|
|
2546
|
use Net::Z3950; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Net::Z3950::AsyncZ::Report; |
|
6
|
|
|
|
|
|
|
require Net::Z3950::AsyncZ; |
|
7
|
|
|
|
|
|
|
use Carp; |
|
8
|
|
|
|
|
|
|
use strict; |
|
9
|
|
|
|
|
|
|
use vars '$AUTOLOAD'; |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @_options = (); |
|
13
|
|
|
|
|
|
|
my %_optiondata = ( |
|
14
|
|
|
|
|
|
|
pipetimeout=> undef, # timeout in seconds for each piped process--default 20 |
|
15
|
|
|
|
|
|
|
interval => undef, # timer interval for each piped process--default 5 |
|
16
|
|
|
|
|
|
|
format => undef, # reference to a callback function that formats each row of a record |
|
17
|
|
|
|
|
|
|
HTML => 0, # (boolean) if true use default HTML formatting, if false format as plain text: see Record.pm |
|
18
|
|
|
|
|
|
|
raw => 0, # (boolean) if true the raw record data is returned unformatted |
|
19
|
|
|
|
|
|
|
startrec => 1, # number of the record with which to start report |
|
20
|
|
|
|
|
|
|
num_to_fetch => 5, # number of records to include in a report |
|
21
|
|
|
|
|
|
|
marc_fields => $Net::Z3950::AsyncZ::Report::std, # default: $std, others are $xtra or $all |
|
22
|
|
|
|
|
|
|
marc_xcl => undef, # reference to hash of MARC fields to exclude from report |
|
23
|
|
|
|
|
|
|
marc_subst=>undef, |
|
24
|
|
|
|
|
|
|
marc_userdef => undef, # reference to user-defined hash of MARC fields for report |
|
25
|
|
|
|
|
|
|
query=>undef, |
|
26
|
|
|
|
|
|
|
utf8=>0, |
|
27
|
|
|
|
|
|
|
_this_server=>undef, |
|
28
|
|
|
|
|
|
|
_this_pid=>undef, |
|
29
|
|
|
|
|
|
|
render => 1, # raw records default to $record->render() |
|
30
|
|
|
|
|
|
|
log=>undef, # path to errors log file |
|
31
|
|
|
|
|
|
|
cb=>undef, # reference to callback function to which records will be sent as available |
|
32
|
|
|
|
|
|
|
querytype =>undef, # Z3950 querytype: default: 'prefix', can be set to'ccl', or 'ccl2rpn' |
|
33
|
|
|
|
|
|
|
preferredRecordSyntax=>Net::Z3950::RecordSyntax::USMARC, |
|
34
|
|
|
|
|
|
|
Z3950_options => undef # reference to hash of additional Z3950 options--these |
|
35
|
|
|
|
|
|
|
# take precedence over the options hash and values set in Async->new |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
|
39
|
|
|
|
|
|
|
my($class, %args) = @_; |
|
40
|
|
|
|
|
|
|
my $opt_ref = { %_optiondata }; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
foreach my $field ( keys %_optiondata ) { |
|
43
|
|
|
|
|
|
|
$opt_ref->{$field} = $args{$field} |
|
44
|
|
|
|
|
|
|
if defined $args{$field}; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
push @_options,$opt_ref; |
|
48
|
|
|
|
|
|
|
my $self = $#_options; |
|
49
|
|
|
|
|
|
|
bless \$self, $class; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub test { |
|
55
|
|
|
|
|
|
|
my $self=@_; |
|
56
|
|
|
|
|
|
|
my $opt_ref = $_options[${$_[0]}]; |
|
57
|
|
|
|
|
|
|
foreach my $fld( keys %$opt_ref ) { |
|
58
|
|
|
|
|
|
|
print $fld, " = ", $opt_ref->{$fld}, "\n", |
|
59
|
|
|
|
|
|
|
if defined $opt_ref->{$fld}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# call: $self->_getFieldValue('field'); |
|
65
|
|
|
|
|
|
|
# returns value if successful, undef if not |
|
66
|
|
|
|
|
|
|
sub _getFieldValue { |
|
67
|
|
|
|
|
|
|
return $_options[${$_[0]}]->{$_[1]} |
|
68
|
|
|
|
|
|
|
if $_[0]->_is_option($_[1]); |
|
69
|
|
|
|
|
|
|
return undef; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# $self->_setFieldValue('field', 'newval'); |
|
74
|
|
|
|
|
|
|
# returns old value, or undef if field is not valid |
|
75
|
|
|
|
|
|
|
sub _setFieldValue |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
my $temp = $_[0]->_getFieldValue($_[1]); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$_options[${$_[0]}]->{$_[1]} = $_[2], return $temp, |
|
80
|
|
|
|
|
|
|
if $_[0]->_is_option($_[1]); |
|
81
|
|
|
|
|
|
|
return undef; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=pod |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->option('field'); |
|
87
|
|
|
|
|
|
|
returns value of field |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$self->option(%hash); |
|
90
|
|
|
|
|
|
|
sets values of fields in hash: field=>value,field=>value. . . |
|
91
|
|
|
|
|
|
|
returns: reference to a hash of old values; |
|
92
|
|
|
|
|
|
|
if the field is not a valid option |
|
93
|
|
|
|
|
|
|
the field's value is set to undef; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Because an old value may have been undefined and returns undef |
|
96
|
|
|
|
|
|
|
you must use either validOption() or invalidOption() |
|
97
|
|
|
|
|
|
|
to determine whether the field is in fact invalid |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub option |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
|
|
|
|
|
|
my( $self, @args) = @_; |
|
105
|
|
|
|
|
|
|
my @temp; |
|
106
|
|
|
|
|
|
|
return $self->_getFieldValue($args[0]) if scalar @args == 1; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my %args = (@args); |
|
109
|
|
|
|
|
|
|
foreach my $fld (keys %args) { |
|
110
|
|
|
|
|
|
|
push @temp, $fld, $self->_setFieldValue($fld, $args{$fld}); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
return {@temp}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# _updateObjectHash() |
|
118
|
|
|
|
|
|
|
# internal function. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# returns a reference to a hash whose key=>value pairs have been |
|
121
|
|
|
|
|
|
|
# set through the options setting mechanisms of Net::Z3950::AsyncZ::_params and which have |
|
122
|
|
|
|
|
|
|
# equivalents in the class object which is passed in the $hash parameter. |
|
123
|
|
|
|
|
|
|
# This enables each class either to reset its own options hash, or to use the |
|
124
|
|
|
|
|
|
|
# Net::Z3950::AsyncZ::_params options, as required by the class code. |
|
125
|
|
|
|
|
|
|
# params: |
|
126
|
|
|
|
|
|
|
# $self: Net::Z3950::AsyncZ::_params object |
|
127
|
|
|
|
|
|
|
# $hash: object of class to be updated |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _updateObjectHash |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
|
|
|
|
|
|
my ($self, $hash) = @_; |
|
132
|
|
|
|
|
|
|
my %matches = (); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
foreach my $key (keys %_optiondata) { |
|
135
|
|
|
|
|
|
|
if( exists $hash->{$key} ) { |
|
136
|
|
|
|
|
|
|
my $value = $self->_getFieldValue($key); |
|
137
|
|
|
|
|
|
|
$matches{$key} = $value if defined $value; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
return \%matches; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub MARCList |
|
145
|
|
|
|
|
|
|
{ |
|
146
|
|
|
|
|
|
|
my($self, $list_ref) = @_; |
|
147
|
|
|
|
|
|
|
$list_ref = $self->_getFieldValue('marc_fields') if !$list_ref; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
foreach my $number (sort keys %{$list_ref}) { |
|
150
|
|
|
|
|
|
|
print $number, " ", $list_ref->{$number}, "\n"; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my %_fn_equiv = ( |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# functions requiring user parameters or returning values |
|
157
|
|
|
|
|
|
|
pipetimeout=>undef, |
|
158
|
|
|
|
|
|
|
interval => undef, |
|
159
|
|
|
|
|
|
|
format =>undef, |
|
160
|
|
|
|
|
|
|
HTML => undef, |
|
161
|
|
|
|
|
|
|
raw => undef, |
|
162
|
|
|
|
|
|
|
startrec =>undef, |
|
163
|
|
|
|
|
|
|
num_to_fetch =>undef, |
|
164
|
|
|
|
|
|
|
marc_fields =>undef, |
|
165
|
|
|
|
|
|
|
marc_xcl =>undef, |
|
166
|
|
|
|
|
|
|
marc_subst=>undef, |
|
167
|
|
|
|
|
|
|
marc_userdef =>undef, |
|
168
|
|
|
|
|
|
|
log=>undef, |
|
169
|
|
|
|
|
|
|
render=>undef, |
|
170
|
|
|
|
|
|
|
query=>undef, |
|
171
|
|
|
|
|
|
|
cb=>undef, |
|
172
|
|
|
|
|
|
|
utf8=>undef, |
|
173
|
|
|
|
|
|
|
querytype =>undef, |
|
174
|
|
|
|
|
|
|
preferredRecordSyntax=>undef, |
|
175
|
|
|
|
|
|
|
Z3950_options=>undef |
|
176
|
|
|
|
|
|
|
); |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my %_fn_predef = ( |
|
180
|
|
|
|
|
|
|
# functions using predefined parameters |
|
181
|
|
|
|
|
|
|
marc_xtra => [ 'marc_fields', $Net::Z3950::AsyncZ::Report::xtra ], |
|
182
|
|
|
|
|
|
|
marc_all => [ 'marc_fields', $Net::Z3950::AsyncZ::Report::all ], |
|
183
|
|
|
|
|
|
|
marc_std => [ 'marc_fields', $Net::Z3950::AsyncZ::Report::std ], |
|
184
|
|
|
|
|
|
|
raw_on => [ 'raw', 1 ], |
|
185
|
|
|
|
|
|
|
raw_off => [ 'raw', 0 ], |
|
186
|
|
|
|
|
|
|
plaintext=> [ 'HTML', 0 ], |
|
187
|
|
|
|
|
|
|
HTML=> [ 'HTML', 1 ], |
|
188
|
|
|
|
|
|
|
prefix => [ 'querytype', 'prefix'], |
|
189
|
|
|
|
|
|
|
ccl=> [ 'querytype', 'ccl'], |
|
190
|
|
|
|
|
|
|
GRS1=> [ 'preferredRecordSyntax', Net::Z3950::RecordSyntax::GRS1], |
|
191
|
|
|
|
|
|
|
USMARC=> [ 'preferredRecordSyntax', Net::Z3950::RecordSyntax::USMARC] |
|
192
|
|
|
|
|
|
|
); |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=pod |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$opt->validOption( |
|
198
|
|
|
|
|
|
|
$opt->invalidOption( |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
These test for validity of options which have been set with the option setting |
|
201
|
|
|
|
|
|
|
functions, either option() or the set_ |
|
202
|
|
|
|
|
|
|
occurs when attempting to set an option which does not exist. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# public form of _is_option(), in case changes need to be made one or the other of these |
|
210
|
|
|
|
|
|
|
sub validOption { &_is_option; } |
|
211
|
|
|
|
|
|
|
sub invalidOption { !&_is_option; } |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# true if value is in %_options array, hence can be set or read |
|
215
|
|
|
|
|
|
|
sub _is_option { exists $_options[${$_[0]}]->{$_[1]}; } |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub _is_fn_equiv { |
|
218
|
|
|
|
|
|
|
exists $_fn_equiv{ $_[1]}; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub _is_fn_predef { |
|
222
|
|
|
|
|
|
|
exists $_fn_predef{ $_[1]}; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# All the AUTOLOAD function equivalents return undef if unsuccessful |
|
227
|
|
|
|
|
|
|
# Autoload carps an error message if an invalid function name is used |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
230
|
|
|
|
|
|
|
no strict "refs"; |
|
231
|
|
|
|
|
|
|
my ($self, $val) = @_; |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
if( $AUTOLOAD =~ /.*::get_(\w+)/) { |
|
234
|
|
|
|
|
|
|
if ($self->_is_option($1)) { |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
my $option = $1; |
|
237
|
|
|
|
|
|
|
*{$AUTOLOAD} = sub { $_[0]->_getFieldValue($option); }; |
|
238
|
|
|
|
|
|
|
return $self->_getFieldValue($1); |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
if( $AUTOLOAD =~ /.*::set_(\w+)/) { |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
if($self->_is_fn_predef($1)) { |
|
245
|
|
|
|
|
|
|
my ($option, $value) = @{$_fn_predef{$1}}; |
|
246
|
|
|
|
|
|
|
*{$AUTOLOAD} = sub { return $_[0]->_setFieldValue($option=>$value); }; |
|
247
|
|
|
|
|
|
|
return $self->_setFieldValue($option=>$value); |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
elsif ($self->_is_fn_equiv($1)) { |
|
250
|
|
|
|
|
|
|
my $option = $1; |
|
251
|
|
|
|
|
|
|
if ($option =~ /utf8/) { |
|
252
|
|
|
|
|
|
|
return if !Net::Z3950::AsyncZ::_setupUTF8(); |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
*{$AUTOLOAD} = sub { return $_[0]->_setFieldValue($option=>$_[1]); }; |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
return $self->_setFieldValue($option=>$val); |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
carp "$AUTOLOAD is not a valid function call\n"; |
|
261
|
|
|
|
|
|
|
return undef; |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
} # AUTOLOAD |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub DESTROY { } |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
1; |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
|