Filename | /usr/lib/perl5/ZOOM.pm |
Statements | Executed 6822 statements in 132ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
200 | 2 | 1 | 5.23ms | 45.4ms | record | ZOOM::ResultSet::
202 | 3 | 1 | 3.30ms | 5.27ms | _check | ZOOM::Connection::
200 | 2 | 1 | 2.28ms | 17.1ms | get | ZOOM::Record::
200 | 1 | 1 | 2.01ms | 2.01ms | _new | ZOOM::Record::
1 | 1 | 1 | 2.01ms | 2.39ms | BEGIN@194 | ZOOM::Exception::
1 | 1 | 1 | 1.84ms | 5.45ms | BEGIN@4 | C4::Context::
175 | 1 | 1 | 1.18ms | 14.8ms | render | ZOOM::Record::
202 | 3 | 1 | 1.15ms | 1.15ms | _rs | ZOOM::ResultSet::
232 | 8 | 1 | 915µs | 915µs | _conn | ZOOM::Connection::
200 | 1 | 1 | 769µs | 769µs | _rec | ZOOM::Record::
1 | 1 | 1 | 490µs | 490µs | CORE:readline (opcode) | ZOOM::Query::CCL2RPN::
1 | 1 | 1 | 364µs | 2.59ms | new | ZOOM::Query::CCL2RPN::
12 | 1 | 1 | 190µs | 67.7ms | event | ZOOM::
25 | 1 | 1 | 190µs | 3.69ms | raw | ZOOM::Record::
8 | 8 | 1 | 139µs | 278µs | option | ZOOM::Options::
11 | 1 | 1 | 136µs | 202µs | last_event | ZOOM::Connection::
1 | 1 | 1 | 63µs | 426µs | BEGIN@3 | C4::Context::
3 | 3 | 2 | 54µs | 92µs | option | ZOOM::Connection::
17 | 3 | 1 | 54µs | 54µs | _opts | ZOOM::Options::
1 | 1 | 1 | 47µs | 151µs | search | ZOOM::Connection::
1 | 1 | 1 | 45µs | 56µs | BEGIN@1 | C4::Context::
11 | 1 | 1 | 45µs | 61µs | ZEND | ZOOM::Event::
1 | 1 | 1 | 40µs | 108µs | new | ZOOM::Options::
1 | 1 | 1 | 37µs | 71µs | size | ZOOM::ResultSet::
3 | 1 | 1 | 37µs | 37µs | CORE:ftsize (opcode) | C4::Context::
3 | 1 | 1 | 30µs | 30µs | CORE:subst (opcode) | C4::Context::
1 | 1 | 1 | 28µs | 82µs | create | ZOOM::Connection::
1 | 1 | 1 | 27µs | 64µs | BEGIN@2 | C4::Context::
1 | 1 | 1 | 22µs | 79µs | connect | ZOOM::Connection::
1 | 1 | 1 | 21µs | 77µs | destroy | ZOOM::ResultSet::
1 | 1 | 1 | 17µs | 17µs | CORE:ftdir (opcode) | C4::Context::
1 | 1 | 1 | 17µs | 67µs | mask_str | ZOOM::Log::
1 | 1 | 1 | 15µs | 15µs | _new | ZOOM::ResultSet::
1 | 1 | 1 | 13µs | 20µs | errcode | ZOOM::Connection::
1 | 1 | 1 | 12µs | 79µs | BEGIN@1107 | ZOOM::Log::
1 | 1 | 1 | 4µs | 4µs | _query | ZOOM::Query::
0 | 0 | 0 | 0s | 0s | BAD_RELATION | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | BAD_RP | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | DOUBLE_QUAL | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | EQ_EXPECTED | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | OK | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | OP_EXPECTED | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | RP_EXPECTED | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | SETNAME_EXPECTED | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | TERM_EXPECTED | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | TRUNC_NOT_BOTH | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | TRUNC_NOT_LEFT | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | TRUNC_NOT_RIGHT | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | UNKNOWN_QUAL | ZOOM::CCL::Error::
0 | 0 | 0 | 0s | 0s | addinfo | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | check | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | diagset | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | errmsg | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | error_x | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | exception | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | is_idle | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | option_binary | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | package | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | peek_event | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | scan | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | scan_pqf | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | search_pqf | ZOOM::Connection::
0 | 0 | 0 | 0s | 0s | CCL_CONFIG | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CCL_PARSE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CLONE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CONNECT | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CONNECTION_LOST | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CQL_PARSE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CQL_TRANSFORM | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CREATE_QUERY | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | DECODE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | ENCODE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | INTERNAL | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | INVALID_QUERY | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | LOGLEVEL | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | MEMORY | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | NONE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | PACKAGE | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | QUERY_CQL | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | QUERY_PQF | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | SCANTERM | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | SORTBY | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | TIMEOUT | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | UNSUPPORTED_PROTOCOL | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | UNSUPPORTED_QUERY | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | ZINIT | ZOOM::Error::
0 | 0 | 0 | 0s | 0s | CONNECT | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | NONE | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | RECV_APDU | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | RECV_DATA | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | RECV_RECORD | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | RECV_SEARCH | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | SEND_APDU | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | SEND_DATA | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | TIMEOUT | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | UNKNOWN | ZOOM::Event::
0 | 0 | 0 | 0s | 0s | addinfo | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | code | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | diagset | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | message | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | render | ZOOM::Exception::
0 | 0 | 0 | 0s | 0s | init | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | init_file | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | init_level | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | init_max_size | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | init_prefix | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | log | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | module_level | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | time_format | ZOOM::Log::
0 | 0 | 0 | 0s | 0s | bool | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | int | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | option_binary | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | set_callback | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | set_int | ZOOM::Options::
0 | 0 | 0 | 0s | 0s | _new | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | _p | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | option | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | send | ZOOM::Package::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Query::CQL2RPN::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Query::CQL::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Query::PQF::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::Query::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Query::
0 | 0 | 0 | 0s | 0s | sortby | ZOOM::Query::
0 | 0 | 0 | 0s | 0s | clone | ZOOM::Record::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::Record::
0 | 0 | 0 | 0s | 0s | error | ZOOM::Record::
0 | 0 | 0 | 0s | 0s | exception | ZOOM::Record::
0 | 0 | 0 | 0s | 0s | new | ZOOM::Record::
0 | 0 | 0 | 0s | 0s | cache_reset | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | new | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | option | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | record_immediate | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | records | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | sort | ZOOM::ResultSet::
0 | 0 | 0 | 0s | 0s | _new | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | _ss | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | destroy | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | display_term | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | new | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | option | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | size | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | term | ZOOM::ScanSet::
0 | 0 | 0 | 0s | 0s | _oops | ZOOM::
0 | 0 | 0 | 0s | 0s | diag_srw_str | ZOOM::
0 | 0 | 0 | 0s | 0s | diag_str | ZOOM::
0 | 0 | 0 | 0s | 0s | event_str | ZOOM::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 3 | 64µs | 2 | 66µs | # spent 56µs (45+11) within C4::Context::BEGIN@1 which was called:
# once (45µs+11µs) by C4::Context::BEGIN@102 at line 1 # spent 56µs making 1 call to C4::Context::BEGIN@1
# spent 11µs making 1 call to strict::import |
2 | 3 | 94µs | 2 | 102µs | # spent 64µs (27+38) within C4::Context::BEGIN@2 which was called:
# once (27µs+38µs) by C4::Context::BEGIN@102 at line 2 # spent 64µs making 1 call to C4::Context::BEGIN@2
# spent 38µs making 1 call to warnings::import |
3 | 3 | 70µs | 2 | 789µs | # spent 426µs (63+363) within C4::Context::BEGIN@3 which was called:
# once (63µs+363µs) by C4::Context::BEGIN@102 at line 3 # spent 426µs making 1 call to C4::Context::BEGIN@3
# spent 363µs making 1 call to Exporter::import |
4 | 3 | 2.44ms | 1 | 5.45ms | # spent 5.45ms (1.84+3.60) within C4::Context::BEGIN@4 which was called:
# once (1.84ms+3.60ms) by C4::Context::BEGIN@102 at line 4 # spent 5.45ms making 1 call to C4::Context::BEGIN@4 |
5 | |||||
6 | |||||
7 | package ZOOM; | ||||
8 | |||||
9 | # Member naming convention: hash-element names which begin with an | ||||
10 | # underscore represent underlying ZOOM-C object descriptors; those | ||||
11 | # which lack them represent Perl's ZOOM objects. (The same convention | ||||
12 | # is used in naming local variables where appropriate.) | ||||
13 | # | ||||
14 | # So, for example, the ZOOM::Connection class has an {_conn} element, | ||||
15 | # which is a pointer to the ZOOM-C Connection object; but the | ||||
16 | # ZOOM::ResultSet class has a {conn} element, which is a reference to | ||||
17 | # the Perl-level Connection object by which it was created. (It may | ||||
18 | # be that we find we have no need for these references, but for now | ||||
19 | # they are retained.) | ||||
20 | # | ||||
21 | # To get at the underlying ZOOM-C connection object of a result-set | ||||
22 | # (if you ever needed to do such a thing, which you probably don't) | ||||
23 | # you'd use $rs->{conn}->_conn(). | ||||
24 | |||||
25 | # ---------------------------------------------------------------------------- | ||||
26 | |||||
27 | # The "Error" package contains constants returned as error-codes. | ||||
28 | package ZOOM::Error; | ||||
29 | sub NONE { Net::Z3950::ZOOM::ERROR_NONE } | ||||
30 | sub CONNECT { Net::Z3950::ZOOM::ERROR_CONNECT } | ||||
31 | sub MEMORY { Net::Z3950::ZOOM::ERROR_MEMORY } | ||||
32 | sub ENCODE { Net::Z3950::ZOOM::ERROR_ENCODE } | ||||
33 | sub DECODE { Net::Z3950::ZOOM::ERROR_DECODE } | ||||
34 | sub CONNECTION_LOST { Net::Z3950::ZOOM::ERROR_CONNECTION_LOST } | ||||
35 | sub ZINIT { Net::Z3950::ZOOM::ERROR_INIT } | ||||
36 | sub INTERNAL { Net::Z3950::ZOOM::ERROR_INTERNAL } | ||||
37 | sub TIMEOUT { Net::Z3950::ZOOM::ERROR_TIMEOUT } | ||||
38 | sub UNSUPPORTED_PROTOCOL { Net::Z3950::ZOOM::ERROR_UNSUPPORTED_PROTOCOL } | ||||
39 | sub UNSUPPORTED_QUERY { Net::Z3950::ZOOM::ERROR_UNSUPPORTED_QUERY } | ||||
40 | sub INVALID_QUERY { Net::Z3950::ZOOM::ERROR_INVALID_QUERY } | ||||
41 | sub CQL_PARSE { Net::Z3950::ZOOM::ERROR_CQL_PARSE } | ||||
42 | sub CQL_TRANSFORM { Net::Z3950::ZOOM::ERROR_CQL_TRANSFORM } | ||||
43 | sub CCL_CONFIG { Net::Z3950::ZOOM::ERROR_CCL_CONFIG } | ||||
44 | sub CCL_PARSE { Net::Z3950::ZOOM::ERROR_CCL_PARSE } | ||||
45 | # The following are added specifically for this OO interface | ||||
46 | sub CREATE_QUERY { 20001 } | ||||
47 | sub QUERY_CQL { 20002 } | ||||
48 | sub QUERY_PQF { 20003 } | ||||
49 | sub SORTBY { 20004 } | ||||
50 | sub CLONE { 20005 } | ||||
51 | sub PACKAGE { 20006 } | ||||
52 | sub SCANTERM { 20007 } | ||||
53 | sub LOGLEVEL { 20008 } | ||||
54 | |||||
55 | # Separate space for CCL errors. Great. | ||||
56 | package ZOOM::CCL::Error; | ||||
57 | sub OK { Net::Z3950::ZOOM::CCL_ERR_OK } | ||||
58 | sub TERM_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED } | ||||
59 | sub RP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_RP_EXPECTED } | ||||
60 | sub SETNAME_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_SETNAME_EXPECTED } | ||||
61 | sub OP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_OP_EXPECTED } | ||||
62 | sub BAD_RP { Net::Z3950::ZOOM::CCL_ERR_BAD_RP } | ||||
63 | sub UNKNOWN_QUAL { Net::Z3950::ZOOM::CCL_ERR_UNKNOWN_QUAL } | ||||
64 | sub DOUBLE_QUAL { Net::Z3950::ZOOM::CCL_ERR_DOUBLE_QUAL } | ||||
65 | sub EQ_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_EQ_EXPECTED } | ||||
66 | sub BAD_RELATION { Net::Z3950::ZOOM::CCL_ERR_BAD_RELATION } | ||||
67 | sub TRUNC_NOT_LEFT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_LEFT } | ||||
68 | sub TRUNC_NOT_BOTH { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_BOTH } | ||||
69 | sub TRUNC_NOT_RIGHT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_RIGHT } | ||||
70 | |||||
71 | # The "Event" package contains constants returned by last_event() | ||||
72 | package ZOOM::Event; | ||||
73 | sub NONE { Net::Z3950::ZOOM::EVENT_NONE } | ||||
74 | sub CONNECT { Net::Z3950::ZOOM::EVENT_CONNECT } | ||||
75 | sub SEND_DATA { Net::Z3950::ZOOM::EVENT_SEND_DATA } | ||||
76 | sub RECV_DATA { Net::Z3950::ZOOM::EVENT_RECV_DATA } | ||||
77 | sub TIMEOUT { Net::Z3950::ZOOM::EVENT_TIMEOUT } | ||||
78 | sub UNKNOWN { Net::Z3950::ZOOM::EVENT_UNKNOWN } | ||||
79 | sub SEND_APDU { Net::Z3950::ZOOM::EVENT_SEND_APDU } | ||||
80 | sub RECV_APDU { Net::Z3950::ZOOM::EVENT_RECV_APDU } | ||||
81 | sub RECV_RECORD { Net::Z3950::ZOOM::EVENT_RECV_RECORD } | ||||
82 | sub RECV_SEARCH { Net::Z3950::ZOOM::EVENT_RECV_SEARCH } | ||||
83 | 11 | 38µs | 11 | 16µs | # spent 61µs (45+16) within ZOOM::Event::ZEND which was called 11 times, avg 6µs/call:
# 11 times (45µs+16µs) by C4::Search::_ZOOM_event_loop at line 2349 of /usr/share/koha/lib/C4/Search.pm, avg 6µs/call # spent 16µs making 11 calls to Net::Z3950::ZOOM::EVENT_END, avg 1µs/call |
84 | |||||
85 | # ---------------------------------------------------------------------------- | ||||
86 | |||||
87 | package ZOOM; | ||||
88 | |||||
89 | sub diag_str { | ||||
90 | my($code) = @_; | ||||
91 | |||||
92 | # Special cases for error specific to the OO layer | ||||
93 | if ($code == ZOOM::Error::CREATE_QUERY) { | ||||
94 | return "can't create query object"; | ||||
95 | } elsif ($code == ZOOM::Error::QUERY_CQL) { | ||||
96 | return "can't set CQL query"; | ||||
97 | } elsif ($code == ZOOM::Error::QUERY_PQF) { | ||||
98 | return "can't set prefix query"; | ||||
99 | } elsif ($code == ZOOM::Error::SORTBY) { | ||||
100 | return "can't set sort-specification"; | ||||
101 | } elsif ($code == ZOOM::Error::CLONE) { | ||||
102 | return "can't clone record"; | ||||
103 | } elsif ($code == ZOOM::Error::PACKAGE) { | ||||
104 | return "can't create package"; | ||||
105 | } elsif ($code == ZOOM::Error::SCANTERM) { | ||||
106 | return "can't retrieve term from scan-set"; | ||||
107 | } elsif ($code == ZOOM::Error::LOGLEVEL) { | ||||
108 | return "unregistered log-level"; | ||||
109 | } | ||||
110 | |||||
111 | return Net::Z3950::ZOOM::diag_str($code); | ||||
112 | } | ||||
113 | |||||
114 | sub diag_srw_str { | ||||
115 | my($code) = @_; | ||||
116 | |||||
117 | return Net::Z3950::ZOOM::diag_srw_str($code); | ||||
118 | } | ||||
119 | |||||
120 | sub event_str { | ||||
121 | return Net::Z3950::ZOOM::event_str(@_); | ||||
122 | } | ||||
123 | |||||
124 | # spent 67.7ms (190µs+67.5) within ZOOM::event which was called 12 times, avg 5.64ms/call:
# 12 times (190µs+67.5ms) by C4::Search::_ZOOM_event_loop at line 2347 of /usr/share/koha/lib/C4/Search.pm, avg 5.64ms/call | ||||
125 | 12 | 10µs | my($connsref) = @_; | ||
126 | |||||
127 | 24 | 61µs | 12 | 39µs | my @_connsref = map { $_->_conn() } @$connsref; # spent 39µs making 12 calls to ZOOM::Connection::_conn, avg 3µs/call |
128 | 12 | 67.6ms | 12 | 67.5ms | return Net::Z3950::ZOOM::event(\@_connsref); # spent 67.5ms making 12 calls to Net::Z3950::ZOOM::event, avg 5.62ms/call |
129 | } | ||||
130 | |||||
131 | sub _oops { | ||||
132 | my($code, $addinfo, $diagset) = @_; | ||||
133 | |||||
134 | die new ZOOM::Exception($code, undef, $addinfo, $diagset); | ||||
135 | } | ||||
136 | |||||
137 | # ---------------------------------------------------------------------------- | ||||
138 | |||||
139 | package ZOOM::Exception; | ||||
140 | |||||
141 | sub new { | ||||
142 | my $class = shift(); | ||||
143 | my($code, $message, $addinfo, $diagset) = @_; | ||||
144 | |||||
145 | $diagset ||= "ZOOM"; | ||||
146 | if (uc($diagset) eq "ZOOM" || uc($diagset) eq "BIB-1") { | ||||
147 | $message ||= ZOOM::diag_str($code); | ||||
148 | } elsif (lc($diagset) eq "info:srw/diagnostic/1") { | ||||
149 | $message ||= ZOOM::diag_srw_str($code); | ||||
150 | } else { | ||||
151 | # Should fill in messages for any other known diagsets. | ||||
152 | $message ||= "(unknown error)"; | ||||
153 | } | ||||
154 | |||||
155 | return bless { | ||||
156 | code => $code, | ||||
157 | message => $message, | ||||
158 | addinfo => $addinfo, | ||||
159 | diagset => $diagset, | ||||
160 | }, $class; | ||||
161 | } | ||||
162 | |||||
163 | sub code { | ||||
164 | my $this = shift(); | ||||
165 | return $this->{code}; | ||||
166 | } | ||||
167 | |||||
168 | sub message { | ||||
169 | my $this = shift(); | ||||
170 | return $this->{message}; | ||||
171 | } | ||||
172 | |||||
173 | sub addinfo { | ||||
174 | my $this = shift(); | ||||
175 | return $this->{addinfo}; | ||||
176 | } | ||||
177 | |||||
178 | sub diagset { | ||||
179 | my $this = shift(); | ||||
180 | return $this->{diagset}; | ||||
181 | } | ||||
182 | |||||
183 | sub render { | ||||
184 | my $this = shift(); | ||||
185 | |||||
186 | my $res = "ZOOM error " . $this->code(); | ||||
187 | $res .= ' "' . $this->message() . '"' if $this->message(); | ||||
188 | $res .= ' (addinfo: "' . $this->addinfo() . '")' if $this->addinfo(); | ||||
189 | $res .= " from diag-set '" . $this->diagset() . "'" if $this->diagset(); | ||||
190 | return $res; | ||||
191 | } | ||||
192 | |||||
193 | # This means that untrapped exceptions render nicely. | ||||
194 | 3 | 8.25ms | 2 | 2.54ms | # spent 2.39ms (2.01+381µs) within ZOOM::Exception::BEGIN@194 which was called:
# once (2.01ms+381µs) by C4::Context::BEGIN@102 at line 194 # spent 2.39ms making 1 call to ZOOM::Exception::BEGIN@194
# spent 154µs making 1 call to overload::import |
195 | |||||
196 | # ---------------------------------------------------------------------------- | ||||
197 | |||||
198 | package ZOOM::Options; | ||||
199 | |||||
200 | # spent 108µs (40+68) within ZOOM::Options::new which was called:
# once (40µs+68µs) by C4::Context::_new_Zconn at line 738 of /usr/share/koha/lib/C4/Context.pm | ||||
201 | 1 | 1µs | my $class = shift(); | ||
202 | 1 | 2µs | my($p1, $p2) = @_; | ||
203 | |||||
204 | 1 | 400ns | my $opts; | ||
205 | 1 | 89µs | 1 | 68µs | if (@_ == 0) { # spent 68µs making 1 call to Net::Z3950::ZOOM::options_create |
206 | $opts = Net::Z3950::ZOOM::options_create(); | ||||
207 | } elsif (@_ == 1) { | ||||
208 | $opts = Net::Z3950::ZOOM::options_create_with_parent($p1->_opts()); | ||||
209 | } elsif (@_ == 2) { | ||||
210 | $opts = Net::Z3950::ZOOM::options_create_with_parent2($p1->_opts(), | ||||
211 | $p2->_opts()); | ||||
212 | } else { | ||||
213 | die "can't make $class object with more than 2 parents"; | ||||
214 | } | ||||
215 | |||||
216 | 1 | 20µs | return bless { | ||
217 | _opts => $opts, | ||||
218 | }, $class; | ||||
219 | } | ||||
220 | |||||
221 | # PRIVATE to this class and ZOOM::Connection::create() and | ||||
222 | # ZOOM::Connection::package() | ||||
223 | # | ||||
224 | sub _opts { | ||||
225 | 17 | 8µs | my $this = shift(); | ||
226 | |||||
227 | 17 | 10µs | my $_opts = $this->{_opts}; | ||
228 | 17 | 6µs | die "{_opts} undefined: has this Options block been destroy()ed?" | ||
229 | if !defined $_opts; | ||||
230 | |||||
231 | 17 | 57µs | return $_opts; | ||
232 | } | ||||
233 | |||||
234 | # spent 278µs (139+139) within ZOOM::Options::option which was called 8 times, avg 35µs/call:
# once (41µs+41µs) by C4::Context::_new_Zconn at line 739 of /usr/share/koha/lib/C4/Context.pm
# once (26µs+23µs) by C4::Context::_new_Zconn at line 741 of /usr/share/koha/lib/C4/Context.pm
# once (11µs+29µs) by C4::Context::_new_Zconn at line 746 of /usr/share/koha/lib/C4/Context.pm
# once (20µs+13µs) by C4::Context::_new_Zconn at line 743 of /usr/share/koha/lib/C4/Context.pm
# once (14µs+13µs) by C4::Context::_new_Zconn at line 740 of /usr/share/koha/lib/C4/Context.pm
# once (10µs+7µs) by C4::Context::_new_Zconn at line 744 of /usr/share/koha/lib/C4/Context.pm
# once (9µs+7µs) by C4::Context::_new_Zconn at line 747 of /usr/share/koha/lib/C4/Context.pm
# once (9µs+6µs) by C4::Context::_new_Zconn at line 745 of /usr/share/koha/lib/C4/Context.pm | ||||
235 | 8 | 5µs | my $this = shift(); | ||
236 | 8 | 10µs | my($key, $value) = @_; | ||
237 | |||||
238 | 8 | 94µs | 16 | 82µs | my $oldval = Net::Z3950::ZOOM::options_get($this->_opts(), $key); # spent 53µs making 8 calls to Net::Z3950::ZOOM::options_get, avg 7µs/call
# spent 28µs making 8 calls to ZOOM::Options::_opts, avg 4µs/call |
239 | 8 | 74µs | 16 | 57µs | Net::Z3950::ZOOM::options_set($this->_opts(), $key, $value) # spent 34µs making 8 calls to Net::Z3950::ZOOM::options_set, avg 4µs/call
# spent 23µs making 8 calls to ZOOM::Options::_opts, avg 3µs/call |
240 | if defined $value; | ||||
241 | |||||
242 | 8 | 39µs | return $oldval; | ||
243 | } | ||||
244 | |||||
245 | sub option_binary { | ||||
246 | my $this = shift(); | ||||
247 | my($key, $value) = @_; | ||||
248 | |||||
249 | my $dummylen = 0; | ||||
250 | my $oldval = Net::Z3950::ZOOM::options_getl($this->_opts(), | ||||
251 | $key, $dummylen); | ||||
252 | Net::Z3950::ZOOM::options_setl($this->_opts(), $key, | ||||
253 | $value, length($value)) | ||||
254 | if defined $value; | ||||
255 | |||||
256 | return $oldval; | ||||
257 | } | ||||
258 | |||||
259 | # This is a bit stupid, since the scalar values that Perl returns from | ||||
260 | # option() can be used as a boolean; but it's just possible that some | ||||
261 | # applications will rely on ZOOM_options_get_bool()'s idiosyncratic | ||||
262 | # interpretation of what constitutes truth. | ||||
263 | # | ||||
264 | sub bool { | ||||
265 | my $this = shift(); | ||||
266 | my($key, $default) = @_; | ||||
267 | |||||
268 | return Net::Z3950::ZOOM::options_get_bool($this->_opts(), $key, $default); | ||||
269 | } | ||||
270 | |||||
271 | # .. and the next two are even more stupid | ||||
272 | sub int { | ||||
273 | my $this = shift(); | ||||
274 | my($key, $default) = @_; | ||||
275 | |||||
276 | return Net::Z3950::ZOOM::options_get_int($this->_opts(), $key, $default); | ||||
277 | } | ||||
278 | |||||
279 | sub set_int { | ||||
280 | my $this = shift(); | ||||
281 | my($key, $value) = @_; | ||||
282 | |||||
283 | Net::Z3950::ZOOM::options_set_int($this->_opts(), $key, $value); | ||||
284 | } | ||||
285 | |||||
286 | # ### Feel guilty. Feel very, very guilty. I've not been able to | ||||
287 | # get the callback memory-management right in "ZOOM.xs", with | ||||
288 | # the result that the values of $function and $udata passed into | ||||
289 | # this function, which are on the stack, have sometimes been | ||||
290 | # freed by the time they're used by __ZOOM_option_callback(), | ||||
291 | # with hilarious results. To avoid this, I copy the values into | ||||
292 | # module-scoped globals, and pass _those_ into the extension | ||||
293 | # function. To avoid overwriting those globals by subsequent | ||||
294 | # calls, I keep all the old ones, pushed onto the @_function and | ||||
295 | # @_udata arrays, which means that THIS FUNCTION LEAKS MEMORY | ||||
296 | # LIKE IT'S GOING OUT OF FASHION. Not nice. One day, I should | ||||
297 | # fix this, but for now there's more important fish to fry. | ||||
298 | # | ||||
299 | 1 | 1µs | my(@_function, @_udata); | ||
300 | sub set_callback { | ||||
301 | my $o1 = shift(); | ||||
302 | my($function, $udata) = @_; | ||||
303 | |||||
304 | push @_function, $function; | ||||
305 | push @_udata, $udata; | ||||
306 | Net::Z3950::ZOOM::options_set_callback($o1->_opts(), | ||||
307 | $_function[-1], $_udata[-1]); | ||||
308 | } | ||||
309 | |||||
310 | sub destroy { | ||||
311 | my $this = shift(); | ||||
312 | |||||
313 | Net::Z3950::ZOOM::options_destroy($this->_opts()); | ||||
314 | $this->{_opts} = undef; | ||||
315 | } | ||||
316 | |||||
317 | |||||
318 | # ---------------------------------------------------------------------------- | ||||
319 | |||||
320 | package ZOOM::Connection; | ||||
321 | |||||
322 | sub new { | ||||
323 | my $class = shift(); | ||||
324 | my($host, $port, @options) = @_; | ||||
325 | |||||
326 | my $conn = $class->create(@options); | ||||
327 | $conn->{host} = $host; | ||||
328 | $conn->{port} = $port; | ||||
329 | |||||
330 | Net::Z3950::ZOOM::connection_connect($conn->_conn(), $host, $port || 0); | ||||
331 | $conn->_check(); | ||||
332 | |||||
333 | return $conn; | ||||
334 | } | ||||
335 | |||||
336 | # PRIVATE to this class, to ZOOM::event() and to ZOOM::Query::CQL2RPN::new() | ||||
337 | # spent 915µs within ZOOM::Connection::_conn which was called 232 times, avg 4µs/call:
# 202 times (817µs+0s) by ZOOM::Connection::_check at line 352, avg 4µs/call
# 12 times (39µs+0s) by ZOOM::event at line 127, avg 3µs/call
# 11 times (36µs+0s) by ZOOM::Connection::last_event at line 530, avg 3µs/call
# 3 times (11µs+0s) by ZOOM::Connection::option at line 456, avg 4µs/call
# once (5µs+0s) by ZOOM::Connection::option at line 457
# once (4µs+0s) by ZOOM::Connection::connect at line 447
# once (3µs+0s) by ZOOM::Connection::search at line 481
# once (2µs+0s) by ZOOM::Connection::errcode at line 424 | ||||
338 | 232 | 143µs | my $this = shift(); | ||
339 | |||||
340 | 232 | 151µs | my $_conn = $this->{_conn}; | ||
341 | 232 | 105µs | die "{_conn} undefined: has this Connection been destroy()ed?" | ||
342 | if !defined $_conn; | ||||
343 | |||||
344 | 232 | 1.10ms | return $_conn; | ||
345 | } | ||||
346 | |||||
347 | # spent 5.27ms (3.30+1.97) within ZOOM::Connection::_check which was called 202 times, avg 26µs/call:
# 200 times (3.27ms+1.95ms) by ZOOM::ResultSet::record at line 740, avg 26µs/call
# once (17µs+14µs) by ZOOM::Connection::connect at line 448
# once (11µs+7µs) by ZOOM::Connection::search at line 483 | ||||
348 | 202 | 132µs | my $this = shift(); | ||
349 | 202 | 133µs | my($always_die_on_error) = @_; | ||
350 | |||||
351 | 202 | 211µs | my($errcode, $errmsg, $addinfo, $diagset) = (undef, "x", "x", "x"); | ||
352 | 202 | 2.72ms | 404 | 1.97ms | $errcode = Net::Z3950::ZOOM::connection_error_x($this->_conn(), $errmsg, # spent 1.15ms making 202 calls to Net::Z3950::ZOOM::connection_error_x, avg 6µs/call
# spent 817µs making 202 calls to ZOOM::Connection::_conn, avg 4µs/call |
353 | $addinfo, $diagset); | ||||
354 | 202 | 719µs | if ($errcode) { | ||
355 | my $exception = new ZOOM::Exception($errcode, $errmsg, $addinfo, | ||||
356 | $diagset); | ||||
357 | if (!$this->option("async") || $always_die_on_error) { | ||||
358 | ZOOM::Log::log("zoom_check", "throwing error $exception"); | ||||
359 | die $exception; | ||||
360 | } else { | ||||
361 | ZOOM::Log::log("zoom_check", "not reporting error $exception"); | ||||
362 | } | ||||
363 | } | ||||
364 | } | ||||
365 | |||||
366 | # This wrapper for _check() is called only from outside the ZOOM | ||||
367 | # module, and therefore only in situations where an asynchronous | ||||
368 | # application is actively asking for an exception to be thrown if an | ||||
369 | # error has been detected. So it passed always_die_on_error=1 to the | ||||
370 | # underlying _check() method. | ||||
371 | # | ||||
372 | sub check { | ||||
373 | my $this = shift(); | ||||
374 | return $this->_check(1); | ||||
375 | } | ||||
376 | |||||
377 | # spent 82µs (28+54) within ZOOM::Connection::create which was called:
# once (28µs+54µs) by C4::Context::_new_Zconn at line 750 of /usr/share/koha/lib/C4/Context.pm | ||||
378 | 1 | 1µs | my $class = shift(); | ||
379 | 1 | 1µs | my(@options) = @_; | ||
380 | |||||
381 | 1 | 500ns | my $_opts; | ||
382 | 1 | 3µs | 1 | 2µs | if (@_ == 1) { # spent 2µs making 1 call to ZOOM::Options::_opts |
383 | $_opts = $_[0]->_opts(); | ||||
384 | } else { | ||||
385 | $_opts = Net::Z3950::ZOOM::options_create(); | ||||
386 | while (@options >= 2) { | ||||
387 | my $key = shift(@options); | ||||
388 | my $val = shift(@options); | ||||
389 | Net::Z3950::ZOOM::options_set($_opts, $key, $val); | ||||
390 | } | ||||
391 | |||||
392 | die "Odd number of options specified" | ||||
393 | if @options; | ||||
394 | } | ||||
395 | |||||
396 | 1 | 60µs | 1 | 52µs | my $_conn = Net::Z3950::ZOOM::connection_create($_opts); # spent 52µs making 1 call to Net::Z3950::ZOOM::connection_create |
397 | 1 | 10µs | my $conn = bless { | ||
398 | host => undef, | ||||
399 | port => undef, | ||||
400 | _conn => $_conn, | ||||
401 | }, $class; | ||||
402 | 1 | 6µs | return $conn; | ||
403 | } | ||||
404 | |||||
405 | sub error_x { | ||||
406 | my $this = shift(); | ||||
407 | |||||
408 | my($errcode, $errmsg, $addinfo, $diagset) = (undef, "dummy", "dummy", "d"); | ||||
409 | $errcode = Net::Z3950::ZOOM::connection_error_x($this->_conn(), $errmsg, | ||||
410 | $addinfo, $diagset); | ||||
411 | return wantarray() ? ($errcode, $errmsg, $addinfo, $diagset) : $errcode; | ||||
412 | } | ||||
413 | |||||
414 | sub exception { | ||||
415 | my $this = shift(); | ||||
416 | |||||
417 | my($errcode, $errmsg, $addinfo, $diagset) = $this->error_x(); | ||||
418 | return undef if $errcode == 0; | ||||
419 | return new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset); | ||||
420 | } | ||||
421 | |||||
422 | # spent 20µs (13+8) within ZOOM::Connection::errcode which was called:
# once (13µs+8µs) by C4::Context::_new_Zconn at line 756 of /usr/share/koha/lib/C4/Context.pm | ||||
423 | 1 | 900ns | my $this = shift(); | ||
424 | 1 | 17µs | 2 | 8µs | return Net::Z3950::ZOOM::connection_errcode($this->_conn()); # spent 6µs making 1 call to Net::Z3950::ZOOM::connection_errcode
# spent 2µs making 1 call to ZOOM::Connection::_conn |
425 | } | ||||
426 | |||||
427 | sub errmsg { | ||||
428 | my $this = shift(); | ||||
429 | return Net::Z3950::ZOOM::connection_errmsg($this->_conn()); | ||||
430 | } | ||||
431 | |||||
432 | sub addinfo { | ||||
433 | my $this = shift(); | ||||
434 | return Net::Z3950::ZOOM::connection_addinfo($this->_conn()); | ||||
435 | } | ||||
436 | |||||
437 | sub diagset { | ||||
438 | my $this = shift(); | ||||
439 | return Net::Z3950::ZOOM::connection_diagset($this->_conn()); | ||||
440 | } | ||||
441 | |||||
442 | # spent 79µs (22+57) within ZOOM::Connection::connect which was called:
# once (22µs+57µs) by C4::Context::_new_Zconn at line 753 of /usr/share/koha/lib/C4/Context.pm | ||||
443 | 1 | 1µs | my $this = shift(); | ||
444 | 1 | 2µs | my($host, $port) = @_; | ||
445 | |||||
446 | 1 | 600ns | $port = 0 if !defined $port; | ||
447 | 1 | 31µs | 2 | 26µs | Net::Z3950::ZOOM::connection_connect($this->_conn(), $host, $port); # spent 22µs making 1 call to Net::Z3950::ZOOM::connection_connect
# spent 4µs making 1 call to ZOOM::Connection::_conn |
448 | 1 | 7µs | 1 | 31µs | $this->_check(); # spent 31µs making 1 call to ZOOM::Connection::_check |
449 | # No return value | ||||
450 | } | ||||
451 | |||||
452 | # spent 92µs (54+38) within ZOOM::Connection::option which was called 3 times, avg 31µs/call:
# once (36µs+24µs) by C4::Context::Zconn at line 702 of /usr/share/koha/lib/C4/Context.pm
# once (12µs+11µs) by ZOOM::Query::CCL2RPN::new at line 637
# once (6µs+4µs) by ZOOM::Query::CCL2RPN::new at line 639 | ||||
453 | 3 | 2µs | my $this = shift(); | ||
454 | 3 | 3µs | my($key, $value) = @_; | ||
455 | |||||
456 | 3 | 27µs | 6 | 21µs | my $oldval = Net::Z3950::ZOOM::connection_option_get($this->_conn(), $key); # spent 11µs making 3 calls to Net::Z3950::ZOOM::connection_option_get, avg 4µs/call
# spent 11µs making 3 calls to ZOOM::Connection::_conn, avg 4µs/call |
457 | 3 | 26µs | 2 | 17µs | Net::Z3950::ZOOM::connection_option_set($this->_conn(), $key, $value) # spent 12µs making 1 call to Net::Z3950::ZOOM::connection_option_set
# spent 5µs making 1 call to ZOOM::Connection::_conn |
458 | if defined $value; | ||||
459 | |||||
460 | 3 | 15µs | return $oldval; | ||
461 | } | ||||
462 | |||||
463 | sub option_binary { | ||||
464 | my $this = shift(); | ||||
465 | my($key, $value) = @_; | ||||
466 | |||||
467 | my $dummylen = 0; | ||||
468 | my $oldval = Net::Z3950::ZOOM::connection_option_getl($this->_conn(), | ||||
469 | $key, $dummylen); | ||||
470 | Net::Z3950::ZOOM::connection_option_setl($this->_conn(), $key, | ||||
471 | $value, length($value)) | ||||
472 | if defined $value; | ||||
473 | |||||
474 | return $oldval; | ||||
475 | } | ||||
476 | |||||
477 | # spent 151µs (47+104) within ZOOM::Connection::search which was called:
# once (47µs+104µs) by C4::Search::getRecords at line 374 of /usr/share/koha/lib/C4/Search.pm | ||||
478 | 1 | 1µs | my $this = shift(); | ||
479 | 1 | 1µs | my($query) = @_; | ||
480 | |||||
481 | 1 | 87µs | 3 | 71µs | my $_rs = Net::Z3950::ZOOM::connection_search($this->_conn(), # spent 64µs making 1 call to Net::Z3950::ZOOM::connection_search
# spent 4µs making 1 call to ZOOM::Query::_query
# spent 3µs making 1 call to ZOOM::Connection::_conn |
482 | $query->_query()); | ||||
483 | 1 | 4µs | 1 | 18µs | $this->_check(); # spent 18µs making 1 call to ZOOM::Connection::_check |
484 | 1 | 11µs | 1 | 15µs | return _new ZOOM::ResultSet($this, $query, $_rs); # spent 15µs making 1 call to ZOOM::ResultSet::_new |
485 | } | ||||
486 | |||||
487 | sub search_pqf { | ||||
488 | my $this = shift(); | ||||
489 | my($pqf) = @_; | ||||
490 | |||||
491 | my $_rs = Net::Z3950::ZOOM::connection_search_pqf($this->_conn(), $pqf); | ||||
492 | $this->_check(); | ||||
493 | return _new ZOOM::ResultSet($this, $pqf, $_rs); | ||||
494 | } | ||||
495 | |||||
496 | sub scan_pqf { | ||||
497 | my $this = shift(); | ||||
498 | my($startterm) = @_; | ||||
499 | |||||
500 | my $_ss = Net::Z3950::ZOOM::connection_scan($this->_conn(), $startterm); | ||||
501 | $this->_check(); | ||||
502 | return _new ZOOM::ScanSet($this, $startterm, $_ss); | ||||
503 | } | ||||
504 | |||||
505 | sub scan { | ||||
506 | my $this = shift(); | ||||
507 | my($query) = @_; | ||||
508 | |||||
509 | my $_ss = Net::Z3950::ZOOM::connection_scan1($this->_conn(), | ||||
510 | $query->_query()); | ||||
511 | $this->_check(); | ||||
512 | return _new ZOOM::ScanSet($this, $query, $_ss); | ||||
513 | } | ||||
514 | |||||
515 | sub package { | ||||
516 | my $this = shift(); | ||||
517 | my($options) = @_; | ||||
518 | |||||
519 | my $_o = defined $options ? $options->_opts() : | ||||
520 | Net::Z3950::ZOOM::options_create(); | ||||
521 | my $_p = Net::Z3950::ZOOM::connection_package($this->_conn(), $_o) | ||||
522 | or ZOOM::_oops(ZOOM::Error::PACKAGE); | ||||
523 | |||||
524 | return _new ZOOM::Package($this, $options, $_p); | ||||
525 | } | ||||
526 | |||||
527 | # spent 202µs (136+67) within ZOOM::Connection::last_event which was called 11 times, avg 18µs/call:
# 11 times (136µs+67µs) by C4::Search::_ZOOM_event_loop at line 2348 of /usr/share/koha/lib/C4/Search.pm, avg 18µs/call | ||||
528 | 11 | 7µs | my $this = shift(); | ||
529 | |||||
530 | 11 | 141µs | 22 | 67µs | return Net::Z3950::ZOOM::connection_last_event($this->_conn()); # spent 36µs making 11 calls to ZOOM::Connection::_conn, avg 3µs/call
# spent 31µs making 11 calls to Net::Z3950::ZOOM::connection_last_event, avg 3µs/call |
531 | } | ||||
532 | |||||
533 | sub is_idle { | ||||
534 | my $this = shift(); | ||||
535 | |||||
536 | return Net::Z3950::ZOOM::connection_is_idle($this->_conn()); | ||||
537 | } | ||||
538 | |||||
539 | sub peek_event { | ||||
540 | my $this = shift(); | ||||
541 | |||||
542 | return Net::Z3950::ZOOM::connection_peek_event($this->_conn()); | ||||
543 | } | ||||
544 | |||||
545 | sub destroy { | ||||
546 | my $this = shift(); | ||||
547 | |||||
548 | Net::Z3950::ZOOM::connection_destroy($this->_conn()); | ||||
549 | $this->{_conn} = undef; | ||||
550 | } | ||||
551 | |||||
552 | |||||
553 | # ---------------------------------------------------------------------------- | ||||
554 | |||||
555 | package ZOOM::Query; | ||||
556 | |||||
557 | sub new { | ||||
558 | my $class = shift(); | ||||
559 | die "You can't create $class objects: it's a virtual base class"; | ||||
560 | } | ||||
561 | |||||
562 | # PRIVATE to this class and ZOOM::Connection::search() | ||||
563 | # spent 4µs within ZOOM::Query::_query which was called:
# once (4µs+0s) by ZOOM::Connection::search at line 481 | ||||
564 | 1 | 500ns | my $this = shift(); | ||
565 | |||||
566 | 1 | 900ns | my $_query = $this->{_query}; | ||
567 | 1 | 400ns | die "{_query} undefined: has this Query been destroy()ed?" | ||
568 | if !defined $_query; | ||||
569 | |||||
570 | 1 | 4µs | return $_query; | ||
571 | } | ||||
572 | |||||
573 | sub sortby { | ||||
574 | my $this = shift(); | ||||
575 | my($sortby) = @_; | ||||
576 | |||||
577 | Net::Z3950::ZOOM::query_sortby($this->_query(), $sortby) == 0 | ||||
578 | or ZOOM::_oops(ZOOM::Error::SORTBY, $sortby); | ||||
579 | } | ||||
580 | |||||
581 | sub destroy { | ||||
582 | my $this = shift(); | ||||
583 | |||||
584 | Net::Z3950::ZOOM::query_destroy($this->_query()); | ||||
585 | $this->{_query} = undef; | ||||
586 | } | ||||
587 | |||||
588 | |||||
589 | package ZOOM::Query::CQL; | ||||
590 | 1 | 14µs | our @ISA = qw(ZOOM::Query); | ||
591 | |||||
592 | sub new { | ||||
593 | my $class = shift(); | ||||
594 | my($string) = @_; | ||||
595 | |||||
596 | my $q = Net::Z3950::ZOOM::query_create() | ||||
597 | or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); | ||||
598 | Net::Z3950::ZOOM::query_cql($q, $string) == 0 | ||||
599 | or ZOOM::_oops(ZOOM::Error::QUERY_CQL, $string); | ||||
600 | |||||
601 | return bless { | ||||
602 | _query => $q, | ||||
603 | }, $class; | ||||
604 | } | ||||
605 | |||||
606 | |||||
607 | package ZOOM::Query::CQL2RPN; | ||||
608 | 1 | 5µs | our @ISA = qw(ZOOM::Query); | ||
609 | |||||
610 | sub new { | ||||
611 | my $class = shift(); | ||||
612 | my($string, $conn) = @_; | ||||
613 | |||||
614 | my $q = Net::Z3950::ZOOM::query_create() | ||||
615 | or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); | ||||
616 | # check() throws the exception we want; but we only want it on failure! | ||||
617 | Net::Z3950::ZOOM::query_cql2rpn($q, $string, $conn->_conn()) == 0 | ||||
618 | or $conn->_check(); | ||||
619 | |||||
620 | return bless { | ||||
621 | _query => $q, | ||||
622 | }, $class; | ||||
623 | } | ||||
624 | |||||
625 | |||||
626 | # We have to work around the retarded ZOOM_query_ccl2rpn() API | ||||
627 | package ZOOM::Query::CCL2RPN; | ||||
628 | 1 | 30µs | our @ISA = qw(ZOOM::Query); | ||
629 | |||||
630 | # spent 2.59ms (364µs+2.23) within ZOOM::Query::CCL2RPN::new which was called:
# once (364µs+2.23ms) by C4::Search::getRecords at line 374 of /usr/share/koha/lib/C4/Search.pm | ||||
631 | 1 | 2µs | my $class = shift(); | ||
632 | 1 | 2µs | my($string, $conn) = @_; | ||
633 | |||||
634 | 1 | 49µs | 1 | 34µs | my $q = Net::Z3950::ZOOM::query_create() # spent 34µs making 1 call to Net::Z3950::ZOOM::query_create |
635 | or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); | ||||
636 | |||||
637 | 1 | 5µs | 1 | 22µs | my $config = $conn->option("cclqual"); # spent 22µs making 1 call to ZOOM::Connection::option |
638 | 1 | 2µs | if (!defined $config) { | ||
639 | 1 | 3µs | 1 | 10µs | my $cclfile = $conn->option("cclfile") # spent 10µs making 1 call to ZOOM::Connection::option |
640 | or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, | ||||
641 | "no 'cclqual' or 'cclfile' specified"); | ||||
642 | 1 | 14µs | 1 | 222µs | my $fh = new IO::File("<$cclfile") # spent 222µs making 1 call to IO::File::new |
643 | or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, | ||||
644 | "can't open cclfile '$cclfile': $!"); | ||||
645 | 1 | 741µs | 1 | 490µs | $config = join("", <$fh>); # spent 490µs making 1 call to ZOOM::Query::CCL2RPN::CORE:readline |
646 | 1 | 27µs | 1 | 30µs | $fh->close(); # spent 30µs making 1 call to IO::Handle::close |
647 | } | ||||
648 | |||||
649 | 1 | 3µs | my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0); | ||
650 | 1 | 1.44ms | 1 | 1.42ms | if (Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $config, # spent 1.42ms making 1 call to Net::Z3950::ZOOM::query_ccl2rpn |
651 | $ccl_errcode, $ccl_errstr, | ||||
652 | $ccl_errpos) < 0) { | ||||
653 | # We have no use for $ccl_errcode or $ccl_errpos | ||||
654 | ZOOM::_oops(ZOOM::Error::CCL_PARSE, $ccl_errstr); | ||||
655 | } | ||||
656 | |||||
657 | 1 | 35µs | return bless { | ||
658 | _query => $q, | ||||
659 | }, $class; | ||||
660 | } | ||||
661 | |||||
662 | |||||
663 | package ZOOM::Query::PQF; | ||||
664 | 1 | 4µs | our @ISA = qw(ZOOM::Query); | ||
665 | |||||
666 | sub new { | ||||
667 | my $class = shift(); | ||||
668 | my($string) = @_; | ||||
669 | |||||
670 | my $q = Net::Z3950::ZOOM::query_create() | ||||
671 | or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); | ||||
672 | Net::Z3950::ZOOM::query_prefix($q, $string) == 0 | ||||
673 | or ZOOM::_oops(ZOOM::Error::QUERY_PQF, $string); | ||||
674 | |||||
675 | return bless { | ||||
676 | _query => $q, | ||||
677 | }, $class; | ||||
678 | } | ||||
679 | |||||
680 | |||||
681 | # ---------------------------------------------------------------------------- | ||||
682 | |||||
683 | package ZOOM::ResultSet; | ||||
684 | |||||
685 | sub new { | ||||
686 | my $class = shift(); | ||||
687 | die "You can't create $class objects directly"; | ||||
688 | } | ||||
689 | |||||
690 | # PRIVATE to ZOOM::Connection::search() and ZOOM::Connection::search_pqf() | ||||
691 | # spent 15µs within ZOOM::ResultSet::_new which was called:
# once (15µs+0s) by ZOOM::Connection::search at line 484 | ||||
692 | 1 | 1µs | my $class = shift(); | ||
693 | 1 | 1µs | my($conn, $query, $_rs) = @_; | ||
694 | |||||
695 | 1 | 15µs | return bless { | ||
696 | conn => $conn, | ||||
697 | query => $query, # This is not currently used, which is | ||||
698 | # just as well since it could be | ||||
699 | # either a string (when the RS is | ||||
700 | # created with search_pqf()) or a | ||||
701 | # ZOOM::Query object (when it's | ||||
702 | # created with search()) | ||||
703 | _rs => $_rs, | ||||
704 | }, $class; | ||||
705 | } | ||||
706 | |||||
707 | # PRIVATE to this class | ||||
708 | sub _rs { | ||||
709 | 202 | 254µs | my $this = shift(); | ||
710 | |||||
711 | 202 | 273µs | my $_rs = $this->{_rs}; | ||
712 | 202 | 91µs | die "{_rs} undefined: has this ResultSet been destroy()ed?" | ||
713 | if !defined $_rs; | ||||
714 | |||||
715 | 202 | 1.11ms | return $_rs; | ||
716 | } | ||||
717 | |||||
718 | sub option { | ||||
719 | my $this = shift(); | ||||
720 | my($key, $value) = @_; | ||||
721 | |||||
722 | my $oldval = Net::Z3950::ZOOM::resultset_option_get($this->_rs(), $key); | ||||
723 | Net::Z3950::ZOOM::resultset_option_set($this->_rs(), $key, $value) | ||||
724 | if defined $value; | ||||
725 | |||||
726 | return $oldval; | ||||
727 | } | ||||
728 | |||||
729 | # spent 71µs (37+34) within ZOOM::ResultSet::size which was called:
# once (37µs+34µs) by C4::Search::_ZOOM_event_loop at line 2351 of /usr/share/koha/lib/C4/Search.pm | ||||
730 | 1 | 1µs | my $this = shift(); | ||
731 | |||||
732 | 1 | 52µs | 2 | 34µs | return Net::Z3950::ZOOM::resultset_size($this->_rs()); # spent 23µs making 1 call to Net::Z3950::ZOOM::resultset_size
# spent 12µs making 1 call to ZOOM::ResultSet::_rs |
733 | } | ||||
734 | |||||
735 | # spent 45.4ms (5.23+40.2) within ZOOM::ResultSet::record which was called 200 times, avg 227µs/call:
# 175 times (4.21ms+8.43ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 506 of /usr/share/koha/lib/C4/Search.pm, avg 72µs/call
# 25 times (1.02ms+31.8ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 490 of /usr/share/koha/lib/C4/Search.pm, avg 1.31ms/call | ||||
736 | 200 | 159µs | my $this = shift(); | ||
737 | 200 | 196µs | my($which) = @_; | ||
738 | |||||
739 | 200 | 33.2ms | 400 | 33.0ms | my $_rec = Net::Z3950::ZOOM::resultset_record($this->_rs(), $which); # spent 31.8ms making 200 calls to Net::Z3950::ZOOM::resultset_record, avg 159µs/call
# spent 1.14ms making 200 calls to ZOOM::ResultSet::_rs, avg 6µs/call |
740 | 200 | 1.15ms | 200 | 5.23ms | $this->{conn}->_check(); # spent 5.23ms making 200 calls to ZOOM::Connection::_check, avg 26µs/call |
741 | |||||
742 | # Even if no error has occurred, I think record() might | ||||
743 | # legitimately return undef if we're running in asynchronous mode | ||||
744 | # and the record just hasn't been retrieved yet. This goes double | ||||
745 | # for record_immediate(). | ||||
746 | 200 | 78µs | return undef if !defined $_rec; | ||
747 | |||||
748 | # For some reason, I have to use the explicit "->" syntax in order | ||||
749 | # to invoke the ZOOM::Record constructor here, even though I don't | ||||
750 | # have to do the same for _new ZOOM::ResultSet above. Weird. | ||||
751 | 200 | 1.53ms | 200 | 2.01ms | return ZOOM::Record->_new($this, $which, $_rec); # spent 2.01ms making 200 calls to ZOOM::Record::_new, avg 10µs/call |
752 | } | ||||
753 | |||||
754 | sub record_immediate { | ||||
755 | my $this = shift(); | ||||
756 | my($which) = @_; | ||||
757 | |||||
758 | my $_rec = Net::Z3950::ZOOM::resultset_record_immediate($this->_rs(), | ||||
759 | $which); | ||||
760 | $this->{conn}->_check(); | ||||
761 | # The record might legitimately not be there yet | ||||
762 | return undef if !defined $_rec; | ||||
763 | |||||
764 | return ZOOM::Record->_new($this, $which, $_rec); | ||||
765 | } | ||||
766 | |||||
767 | sub cache_reset { | ||||
768 | my $this = shift(); | ||||
769 | |||||
770 | Net::Z3950::ZOOM::resultset_cache_reset($this->_rs()); | ||||
771 | } | ||||
772 | |||||
773 | sub records { | ||||
774 | my $this = shift(); | ||||
775 | my($start, $count, $return_records) = @_; | ||||
776 | |||||
777 | # If the request is out of range, ZOOM-C will currently (as of YAZ | ||||
778 | # 2.1.38) no-op: it understandably refuses to build and send a | ||||
779 | # known-bad APDU, but it doesn't set a diagnostic as it ought. So | ||||
780 | # for now, we do it here. It would be more polite to stash the | ||||
781 | # error-code in the ZOOM-C connection object for subsequent | ||||
782 | # discovery (which is what ZOOM-C will presumably do itself when | ||||
783 | # it's fixed) but since there is no API that allows us to do that, | ||||
784 | # we just have to throw the exception right now. That's probably | ||||
785 | # OK for synchronous applications, but not really for | ||||
786 | # multiplexers. | ||||
787 | my $size = $this->size(); | ||||
788 | if ($start + $count-1 >= $size) { | ||||
789 | # BIB-1 diagnostic 13 is "Present request out-of-range" | ||||
790 | ZOOM::_oops(13, undef, "BIB-1"); | ||||
791 | } | ||||
792 | |||||
793 | my $raw = Net::Z3950::ZOOM::resultset_records($this->_rs(), $start, $count, | ||||
794 | $return_records); | ||||
795 | # By design, $raw may be undefined (if $return_records is true) | ||||
796 | return undef if !defined $raw; | ||||
797 | |||||
798 | # We need to package up the returned records in ZOOM::Record objects | ||||
799 | my @res = (); | ||||
800 | for my $i (0 .. @$raw-1) { | ||||
801 | my $_rec = $raw->[$i]; | ||||
802 | if (!defined $_rec) { | ||||
803 | push @res, undef; | ||||
804 | } else { | ||||
805 | push @res, ZOOM::Record->_new($this, $start+$i, $_rec); | ||||
806 | } | ||||
807 | } | ||||
808 | |||||
809 | return \@res; | ||||
810 | } | ||||
811 | |||||
812 | sub sort { | ||||
813 | my $this = shift(); | ||||
814 | my($sort_type, $sort_spec) = @_; | ||||
815 | |||||
816 | return Net::Z3950::ZOOM::resultset_sort1($this->_rs(), | ||||
817 | $sort_type, $sort_spec); | ||||
818 | } | ||||
819 | |||||
820 | # spent 77µs (21+56) within ZOOM::ResultSet::destroy which was called:
# once (21µs+56µs) by C4::Search::_ZOOM_event_loop at line 2359 of /usr/share/koha/lib/C4/Search.pm | ||||
821 | 1 | 800ns | my $this = shift(); | ||
822 | |||||
823 | 1 | 65µs | 2 | 56µs | Net::Z3950::ZOOM::resultset_destroy($this->_rs()); # spent 51µs making 1 call to Net::Z3950::ZOOM::resultset_destroy
# spent 5µs making 1 call to ZOOM::ResultSet::_rs |
824 | 1 | 5µs | $this->{_rs} = undef; | ||
825 | } | ||||
826 | |||||
827 | |||||
828 | # ---------------------------------------------------------------------------- | ||||
829 | |||||
830 | package ZOOM::Record; | ||||
831 | |||||
832 | sub new { | ||||
833 | my $class = shift(); | ||||
834 | die "You can't create $class objects directly"; | ||||
835 | } | ||||
836 | |||||
837 | # PRIVATE to ZOOM::ResultSet::record(), | ||||
838 | # ZOOM::ResultSet::record_immediate(), ZOOM::ResultSet::records() and | ||||
839 | # ZOOM::Record::clone() | ||||
840 | # | ||||
841 | # spent 2.01ms within ZOOM::Record::_new which was called 200 times, avg 10µs/call:
# 200 times (2.01ms+0s) by ZOOM::ResultSet::record at line 751, avg 10µs/call | ||||
842 | 200 | 199µs | my $class = shift(); | ||
843 | 200 | 205µs | my($rs, $which, $_rec) = @_; | ||
844 | |||||
845 | 200 | 1.94ms | return bless { | ||
846 | rs => $rs, | ||||
847 | which => $which, | ||||
848 | _rec => $_rec, | ||||
849 | }, $class; | ||||
850 | } | ||||
851 | |||||
852 | # PRIVATE to this class | ||||
853 | # spent 769µs within ZOOM::Record::_rec which was called 200 times, avg 4µs/call:
# 200 times (769µs+0s) by ZOOM::Record::get at line 899, avg 4µs/call | ||||
854 | 200 | 83µs | my $this = shift(); | ||
855 | |||||
856 | 200 | 180µs | my $_rec = $this->{_rec}; | ||
857 | 200 | 112µs | die "{_rec} undefined: has this Record been destroy()ed?" | ||
858 | if !defined $_rec; | ||||
859 | |||||
860 | 200 | 847µs | return $_rec; | ||
861 | } | ||||
862 | |||||
863 | sub error { | ||||
864 | my $this = shift(); | ||||
865 | |||||
866 | my($errcode, $errmsg, $addinfo, $diagset) = (undef, "dummy", "dummy", "d"); | ||||
867 | $errcode = Net::Z3950::ZOOM::record_error($this->_rec(), $errmsg, | ||||
868 | $addinfo, $diagset); | ||||
869 | |||||
870 | return wantarray() ? ($errcode, $errmsg, $addinfo, $diagset) : $errcode; | ||||
871 | } | ||||
872 | |||||
873 | sub exception { | ||||
874 | my $this = shift(); | ||||
875 | |||||
876 | my($errcode, $errmsg, $addinfo, $diagset) = $this->error(); | ||||
877 | return undef if $errcode == 0; | ||||
878 | return new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset); | ||||
879 | } | ||||
880 | |||||
881 | |||||
882 | # spent 14.8ms (1.18+13.6) within ZOOM::Record::render which was called 175 times, avg 84µs/call:
# 175 times (1.18ms+13.6ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 506 of /usr/share/koha/lib/C4/Search.pm, avg 84µs/call | ||||
883 | 175 | 143µs | my $this = shift(); | ||
884 | |||||
885 | 175 | 838µs | 175 | 13.6ms | return $this->get("render", @_); # spent 13.6ms making 175 calls to ZOOM::Record::get, avg 78µs/call |
886 | } | ||||
887 | |||||
888 | # spent 3.69ms (190µs+3.50) within ZOOM::Record::raw which was called 25 times, avg 147µs/call:
# 25 times (190µs+3.50ms) by C4::Search::__ANON__[/usr/share/koha/lib/C4/Search.pm:670] at line 490 of /usr/share/koha/lib/C4/Search.pm, avg 147µs/call | ||||
889 | 25 | 26µs | my $this = shift(); | ||
890 | |||||
891 | 25 | 155µs | 25 | 3.50ms | return $this->get("raw", @_); # spent 3.50ms making 25 calls to ZOOM::Record::get, avg 140µs/call |
892 | } | ||||
893 | |||||
894 | sub get { | ||||
895 | 200 | 90µs | my $this = shift(); | ||
896 | 200 | 149µs | my($type, $args) = @_; | ||
897 | |||||
898 | 200 | 66µs | $type = "$type;$args" if defined $args; | ||
899 | 200 | 1.43ms | 400 | 14.8ms | return Net::Z3950::ZOOM::record_get($this->_rec(), $type); # spent 14.0ms making 200 calls to Net::Z3950::ZOOM::record_get, avg 70µs/call
# spent 769µs making 200 calls to ZOOM::Record::_rec, avg 4µs/call |
900 | } | ||||
901 | |||||
902 | sub clone { | ||||
903 | my $this = shift(); | ||||
904 | |||||
905 | my $raw = Net::Z3950::ZOOM::record_clone($this->_rec()) | ||||
906 | or ZOOM::_oops(ZOOM::Error::CLONE); | ||||
907 | |||||
908 | # Arg 1 (rs) is undefined as the new record doesn't belong to an RS | ||||
909 | return _new ZOOM::Record(undef, undef, $raw); | ||||
910 | } | ||||
911 | |||||
912 | sub destroy { | ||||
913 | my $this = shift(); | ||||
914 | |||||
915 | Net::Z3950::ZOOM::record_destroy($this->_rec()); | ||||
916 | $this->{_rec} = undef; | ||||
917 | } | ||||
918 | |||||
919 | |||||
920 | # ---------------------------------------------------------------------------- | ||||
921 | |||||
922 | package ZOOM::ScanSet; | ||||
923 | |||||
924 | sub new { | ||||
925 | my $class = shift(); | ||||
926 | die "You can't create $class objects directly"; | ||||
927 | } | ||||
928 | |||||
929 | # PRIVATE to ZOOM::Connection::scan(), | ||||
930 | sub _new { | ||||
931 | my $class = shift(); | ||||
932 | my($conn, $startterm, $_ss) = @_; | ||||
933 | |||||
934 | return bless { | ||||
935 | conn => $conn, | ||||
936 | startterm => $startterm,# This is not currently used, which is | ||||
937 | # just as well since it could be | ||||
938 | # either a string (when the SS is | ||||
939 | # created with scan()) or a | ||||
940 | # ZOOM::Query object (when it's | ||||
941 | # created with scan1()) | ||||
942 | _ss => $_ss, | ||||
943 | }, $class; | ||||
944 | } | ||||
945 | |||||
946 | # PRIVATE to this class | ||||
947 | sub _ss { | ||||
948 | my $this = shift(); | ||||
949 | |||||
950 | my $_ss = $this->{_ss}; | ||||
951 | die "{_ss} undefined: has this ScanSet been destroy()ed?" | ||||
952 | if !defined $_ss; | ||||
953 | |||||
954 | return $_ss; | ||||
955 | } | ||||
956 | |||||
957 | sub option { | ||||
958 | my $this = shift(); | ||||
959 | my($key, $value) = @_; | ||||
960 | |||||
961 | my $oldval = Net::Z3950::ZOOM::scanset_option_get($this->_ss(), $key); | ||||
962 | Net::Z3950::ZOOM::scanset_option_set($this->_ss(), $key, $value) | ||||
963 | if defined $value; | ||||
964 | |||||
965 | return $oldval; | ||||
966 | } | ||||
967 | |||||
968 | sub size { | ||||
969 | my $this = shift(); | ||||
970 | |||||
971 | return Net::Z3950::ZOOM::scanset_size($this->_ss()); | ||||
972 | } | ||||
973 | |||||
974 | sub term { | ||||
975 | my $this = shift(); | ||||
976 | my($which) = @_; | ||||
977 | |||||
978 | my($occ, $len) = (0, 0); | ||||
979 | my $term = Net::Z3950::ZOOM::scanset_term($this->_ss(), $which, | ||||
980 | $occ, $len) | ||||
981 | or ZOOM::_oops(ZOOM::Error::SCANTERM); | ||||
982 | |||||
983 | die "length of term '$term' differs from returned len=$len" | ||||
984 | if length($term) != $len; | ||||
985 | |||||
986 | return ($term, $occ); | ||||
987 | } | ||||
988 | |||||
989 | sub display_term { | ||||
990 | my $this = shift(); | ||||
991 | my($which) = @_; | ||||
992 | |||||
993 | my($occ, $len) = (0, 0); | ||||
994 | my $term = Net::Z3950::ZOOM::scanset_display_term($this->_ss(), $which, | ||||
995 | $occ, $len) | ||||
996 | or ZOOM::_oops(ZOOM::Error::SCANTERM); | ||||
997 | |||||
998 | die "length of display term '$term' differs from returned len=$len" | ||||
999 | if length($term) != $len; | ||||
1000 | |||||
1001 | return ($term, $occ); | ||||
1002 | } | ||||
1003 | |||||
1004 | sub destroy { | ||||
1005 | my $this = shift(); | ||||
1006 | |||||
1007 | Net::Z3950::ZOOM::scanset_destroy($this->_ss()); | ||||
1008 | $this->{_ss} = undef; | ||||
1009 | } | ||||
1010 | |||||
1011 | |||||
1012 | # ---------------------------------------------------------------------------- | ||||
1013 | |||||
1014 | package ZOOM::Package; | ||||
1015 | |||||
1016 | sub new { | ||||
1017 | my $class = shift(); | ||||
1018 | die "You can't create $class objects directly"; | ||||
1019 | } | ||||
1020 | |||||
1021 | # PRIVATE to ZOOM::Connection::package(), | ||||
1022 | sub _new { | ||||
1023 | my $class = shift(); | ||||
1024 | my($conn, $options, $_p) = @_; | ||||
1025 | |||||
1026 | return bless { | ||||
1027 | conn => $conn, | ||||
1028 | options => $options, | ||||
1029 | _p => $_p, | ||||
1030 | }, $class; | ||||
1031 | } | ||||
1032 | |||||
1033 | # PRIVATE to this class | ||||
1034 | sub _p { | ||||
1035 | my $this = shift(); | ||||
1036 | |||||
1037 | my $_p = $this->{_p}; | ||||
1038 | die "{_p} undefined: has this Package been destroy()ed?" | ||||
1039 | if !defined $_p; | ||||
1040 | |||||
1041 | return $_p; | ||||
1042 | } | ||||
1043 | |||||
1044 | sub option { | ||||
1045 | my $this = shift(); | ||||
1046 | my($key, $value) = @_; | ||||
1047 | |||||
1048 | my $oldval = Net::Z3950::ZOOM::package_option_get($this->_p(), $key); | ||||
1049 | Net::Z3950::ZOOM::package_option_set($this->_p(), $key, $value) | ||||
1050 | if defined $value; | ||||
1051 | |||||
1052 | return $oldval; | ||||
1053 | } | ||||
1054 | |||||
1055 | sub send { | ||||
1056 | my $this = shift(); | ||||
1057 | my($type) = @_; | ||||
1058 | |||||
1059 | Net::Z3950::ZOOM::package_send($this->_p(), $type); | ||||
1060 | $this->{conn}->_check(); | ||||
1061 | } | ||||
1062 | |||||
1063 | sub destroy { | ||||
1064 | my $this = shift(); | ||||
1065 | |||||
1066 | Net::Z3950::ZOOM::package_destroy($this->_p()); | ||||
1067 | $this->{_p} = undef; | ||||
1068 | } | ||||
1069 | |||||
1070 | |||||
1071 | # There follows trivial support for YAZ logging. This is wired out | ||||
1072 | # into the Net::Z3950::ZOOM package, and we here provide wrapper | ||||
1073 | # functions -- nothing more than aliases, really -- in the ZOOM::Log | ||||
1074 | # package. There really is no point in inventing an OO interface. | ||||
1075 | # | ||||
1076 | # Passing @_ directly to the underlying Net::Z3950::ZOOM::* functions | ||||
1077 | # doesn't work, for reasons that I can't begin to fathom, and that | ||||
1078 | # don't particularly interest me. Unpacking into scalars and passing | ||||
1079 | # those _does_ work, so that's what we do. | ||||
1080 | |||||
1081 | package ZOOM::Log; | ||||
1082 | |||||
1083 | 2 | 68µs | 1 | 50µs | # spent 67µs (17+50) within ZOOM::Log::mask_str which was called:
# once (17µs+50µs) by ZOOM::Log::BEGIN@1107 at line 1107 # spent 50µs making 1 call to Net::Z3950::ZOOM::yaz_log_mask_str |
1084 | sub module_level { my($a) = @_; Net::Z3950::ZOOM::yaz_log_module_level($a); } | ||||
1085 | sub init { my($a, $b, $c) = @_; | ||||
1086 | Net::Z3950::ZOOM::yaz_log_init($a, $b, $c) } | ||||
1087 | sub init_file { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_file($a) } | ||||
1088 | sub init_level { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_level($a) } | ||||
1089 | sub init_prefix { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_prefix($a) } | ||||
1090 | sub time_format { my($a) = @_; Net::Z3950::ZOOM::yaz_log_time_format($a) } | ||||
1091 | sub init_max_size { my($a) = @_; Net::Z3950::ZOOM::yaz_log_init_max_size($a) } | ||||
1092 | |||||
1093 | sub log { | ||||
1094 | my($level, @message) = @_; | ||||
1095 | |||||
1096 | if ($level !~ /^(0x)?\d+$/) { | ||||
1097 | # Assuming its log-level name, we look it up. | ||||
1098 | my $num = module_level($level); | ||||
1099 | ZOOM::_oops(ZOOM::Error::LOGLEVEL, $level) | ||||
1100 | if $num == 0; | ||||
1101 | $level = $num; | ||||
1102 | } | ||||
1103 | |||||
1104 | Net::Z3950::ZOOM::yaz_log($level, join("", @message)); | ||||
1105 | } | ||||
1106 | |||||
1107 | 1 | 58µs | 2 | 145µs | # spent 79µs (12+67) within ZOOM::Log::BEGIN@1107 which was called:
# once (12µs+67µs) by C4::Context::BEGIN@102 at line 1107 # spent 79µs making 1 call to ZOOM::Log::BEGIN@1107
# spent 67µs making 1 call to ZOOM::Log::mask_str |
1108 | |||||
1109 | 1 | 8µs | 1; | ||
# spent 17µs within C4::Context::CORE:ftdir which was called:
# once (17µs+0s) by C4::Context::KOHAVERSION at line 217 of /usr/share/koha/lib/C4/Context.pm | |||||
# spent 37µs within C4::Context::CORE:ftsize which was called 3 times, avg 12µs/call:
# 3 times (37µs+0s) by C4::Context::new at line 364 of /usr/share/koha/lib/C4/Context.pm, avg 12µs/call | |||||
# spent 30µs within C4::Context::CORE:subst which was called 3 times, avg 10µs/call:
# 3 times (30µs+0s) by C4::Context::AUTOLOAD at line 658 of /usr/share/koha/lib/C4/Context.pm, avg 10µs/call | |||||
# spent 490µs within ZOOM::Query::CCL2RPN::CORE:readline which was called:
# once (490µs+0s) by ZOOM::Query::CCL2RPN::new at line 645 |