Filename | /usr/local/lib/site_perl/Mentat/Storage.pm |
Statements | Executed 19 statements in 543µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 15µs | BEGIN@2 | Mentat::Storage::
1 | 1 | 1 | 10µs | 8.84ms | new | Mentat::Storage::
1 | 1 | 1 | 7µs | 30µs | BEGIN@57 | Mentat::Storage::
1 | 1 | 1 | 7µs | 12µs | BEGIN@3 | Mentat::Storage::
1 | 1 | 1 | 7µs | 44µs | BEGIN@56 | Mentat::Storage::
1 | 1 | 1 | 7µs | 37µs | BEGIN@82 | Mentat::Storage::
1 | 1 | 1 | 4µs | 4µs | BEGIN@81 | Mentat::Storage::
1 | 1 | 1 | 2µs | 2µs | END | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | _init | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | count | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | delete | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | disconnect | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | fetch | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | find | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | insert | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | reconnect | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | remove | Mentat::Storage::
0 | 0 | 0 | 0s | 0s | update | Mentat::Storage::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Mentat::Storage; | ||||
2 | 2 | 23µs | 2 | 18µs | # spent 15µs (12+3) within Mentat::Storage::BEGIN@2 which was called:
# once (12µs+3µs) by Mentat::Storage::Mongo::BEGIN@166 at line 2 # spent 15µs making 1 call to Mentat::Storage::BEGIN@2
# spent 3µs making 1 call to strict::import |
3 | 2 | 43µs | 2 | 17µs | # spent 12µs (7+5) within Mentat::Storage::BEGIN@3 which was called:
# once (7µs+5µs) by Mentat::Storage::Mongo::BEGIN@166 at line 3 # spent 12µs making 1 call to Mentat::Storage::BEGIN@3
# spent 5µs making 1 call to warnings::import |
4 | |||||
5 | #******************************************************************************* | ||||
6 | # DOCUMENTATION SECTION | ||||
7 | #******************************************************************************* | ||||
8 | |||||
9 | =head1 NAME | ||||
10 | |||||
11 | Mentat::Storage - Base module for all Mentat object storage engines | ||||
12 | |||||
13 | =head1 SYNOPSIS | ||||
14 | |||||
15 | use Mentat::Storage; | ||||
16 | |||||
17 | use vars qw(@ISA); | ||||
18 | @ISA = ('Mentat::Storage'); | ||||
19 | |||||
20 | # Now implement the mandatory interface | ||||
21 | |||||
22 | =head1 DESCRIPTION | ||||
23 | |||||
24 | This module is the base class for all Mentat::Storage engines. | ||||
25 | |||||
26 | =head1 AUTHOR | ||||
27 | |||||
28 | Jan Mach | ||||
29 | Cesnet, z.s.p.o | ||||
30 | jan.mach@cesnet.cz | ||||
31 | http://www.cesnet.cz | ||||
32 | |||||
33 | =head1 COPYRIGHT | ||||
34 | |||||
35 | This program is free software; you can redistribute | ||||
36 | it and/or modify it under the same terms as Perl itself. | ||||
37 | |||||
38 | The full text of the license can be found in the | ||||
39 | LICENSE file included with this module. | ||||
40 | |||||
41 | =head1 SEE ALSO | ||||
42 | |||||
43 | perl(1). | ||||
44 | |||||
45 | =head1 FUNCTION REFERENCE | ||||
46 | |||||
47 | =over 4 | ||||
48 | |||||
49 | =cut | ||||
50 | |||||
51 | #******************************************************************************* | ||||
52 | # LIBRARY LOADING SECTION | ||||
53 | #******************************************************************************* | ||||
54 | |||||
55 | #-- Perl core modules ---------------------------------------------------------# | ||||
56 | 2 | 26µs | 2 | 82µs | # spent 44µs (7+38) within Mentat::Storage::BEGIN@56 which was called:
# once (7µs+38µs) by Mentat::Storage::Mongo::BEGIN@166 at line 56 # spent 44µs making 1 call to Mentat::Storage::BEGIN@56
# spent 38µs making 1 call to Exporter::import |
57 | 2 | 46µs | 2 | 53µs | # spent 30µs (7+23) within Mentat::Storage::BEGIN@57 which was called:
# once (7µs+23µs) by Mentat::Storage::Mongo::BEGIN@166 at line 57 # spent 30µs making 1 call to Mentat::Storage::BEGIN@57
# spent 23µs making 1 call to Exporter::import |
58 | |||||
59 | #use Data::Dumper; #-+-> DEVEL ONLY <-+-# | ||||
60 | #use Smart::Comments; #-+-> DEVEL ONLY <-+-# | ||||
61 | |||||
62 | #-- Perl CPAN modules ---------------------------------------------------------# | ||||
63 | |||||
64 | #-- Custom application modules ------------------------------------------------# | ||||
65 | |||||
66 | #******************************************************************************* | ||||
67 | # CONSTANTS AND GLOBAL VARIABLES DEFINITION SECTION | ||||
68 | #******************************************************************************* | ||||
69 | |||||
70 | #-- Constants -----------------------------------------------------------------# | ||||
71 | |||||
72 | #-- Static public class variables (our) ---------------------------------------# | ||||
73 | |||||
74 | #-- Static protected class variables (my) -------------------------------------# | ||||
75 | |||||
76 | #******************************************************************************* | ||||
77 | # INITIALIZATION AND CLEANUP SECTION | ||||
78 | #******************************************************************************* | ||||
79 | |||||
80 | #-- Module initializations ----------------------------------------------------# | ||||
81 | # spent 4µs within Mentat::Storage::BEGIN@81 which was called:
# once (4µs+0s) by Mentat::Storage::Mongo::BEGIN@166 at line 85 | ||||
82 | 2 | 30µs | 2 | 67µs | # spent 37µs (7+30) within Mentat::Storage::BEGIN@82 which was called:
# once (7µs+30µs) by Mentat::Storage::Mongo::BEGIN@166 at line 82 # spent 37µs making 1 call to Mentat::Storage::BEGIN@82
# spent 30µs making 1 call to vars::import |
83 | 1 | 400ns | $VERSION = '0.6'; | ||
84 | 1 | 3µs | $DEVEL = 0; | ||
85 | 1 | 356µs | 1 | 4µs | } # spent 4µs making 1 call to Mentat::Storage::BEGIN@81 |
86 | |||||
87 | |||||
88 | #-- Module clean-up code (global destructor) ----------------------------------# | ||||
89 | 1 | 2µs | # spent 2µs within Mentat::Storage::END which was called:
# once (2µs+0s) by main::RUNTIME at line 0 of mentat.storage.mongo.pl | ||
90 | |||||
91 | } | ||||
92 | |||||
93 | #******************************************************************************* | ||||
94 | # IMPLEMENTATION SECTION | ||||
95 | #******************************************************************************* | ||||
96 | |||||
97 | =item new() [PUBLIC,STATIC] | ||||
98 | |||||
99 | Usage : my $instance = Mentat::Storage->new() | ||||
100 | Purpose : Create and return reference to the new instance | ||||
101 | Arguments : Same as the the _init() method | ||||
102 | Throws : Dies, if invoked on object | ||||
103 | Comments : Internally uses _init() method | ||||
104 | See Also : _init() method | ||||
105 | |||||
106 | =cut | ||||
107 | |||||
108 | sub new | ||||
109 | # spent 8.84ms (10µs+8.83) within Mentat::Storage::new which was called:
# once (10µs+8.83ms) by main::RUNTIME at line 24 of mentat.storage.mongo.pl | ||||
110 | 1 | 400ns | my $class = shift; | ||
111 | 1 | 3µs | 1 | 600ns | confess "Class method not invoked on class" if blessed($class); # spent 600ns making 1 call to Scalar::Util::blessed |
112 | 1 | 3µs | my $self = bless ({}, $class); | ||
113 | 1 | 1µs | 1 | 8.83ms | $self->_init(@_); # spent 8.83ms making 1 call to Mentat::Storage::Mongo::_init |
114 | 1 | 3µs | return $self; | ||
115 | } | ||||
116 | |||||
117 | =item insert($) [PUBLIC,ABSTRACT] | ||||
118 | |||||
119 | Usage : my ($record_id, $error) = $storage->insert($object); | ||||
120 | Purpose : Insert the given object into storage | ||||
121 | Arguments : MIXED $object - object to be stored into storage | ||||
122 | Returns : STRING $oid - ID of the inserted object on SUCCESS, undef on FAILURE | ||||
123 | STRING $error - undef on SUCCESS, error string on failure | ||||
124 | Throws : Dies, if not invoked on instance | ||||
125 | Croaks on insert failure | ||||
126 | Comments : This method dies in case of insert failure, it must be taken care of on higher levels ! | ||||
127 | |||||
128 | =cut | ||||
129 | |||||
130 | sub insert($) | ||||
131 | { | ||||
132 | my $self = shift; | ||||
133 | confess "Method needs implementation in child class"; | ||||
134 | } | ||||
135 | |||||
136 | =item fetch($) [PUBLIC,ABSTRACT] | ||||
137 | |||||
138 | Usage : my $object = $storage->fetch($oid); | ||||
139 | Purpose : Fetch the Mentat message with given ID from storage | ||||
140 | Arguments : STRING $oid - unique identifier of the object in storage | ||||
141 | Returns : HASH REFERENCE $object reference on SUCCESS, | ||||
142 | undef if object with given ID was not found, | ||||
143 | Throws : Dies, if not invoked on instance | ||||
144 | Croaks on query failure | ||||
145 | |||||
146 | =cut | ||||
147 | |||||
148 | sub fetch($) | ||||
149 | { | ||||
150 | my $self = shift; | ||||
151 | confess "Method needs implementation in child class"; | ||||
152 | } | ||||
153 | |||||
154 | =item update($$;$) [PUBLIC,ABSTRACT] | ||||
155 | |||||
156 | Usage : my $result = $storage->update($filter, $values, $options); | ||||
157 | Purpose : Update the existing object in the storage | ||||
158 | Arguments : HASH REFERENCE $filter - Update filter [MANDATORY] | ||||
159 | HASH REFERENCE $values - Object values [MANDATORY] | ||||
160 | HASH REFERENCE $options - Update options [OPTIONAL] | ||||
161 | Returns : HASH REFERENCE containing information about the operation result: | ||||
162 | ok => success flag | ||||
163 | n => number of affected items | ||||
164 | err => error flag | ||||
165 | Throws : Dies, if not invoked on instance | ||||
166 | |||||
167 | =cut | ||||
168 | |||||
169 | sub update($$;$) | ||||
170 | { | ||||
171 | my $self = shift; | ||||
172 | confess "Method needs implementation in child class"; | ||||
173 | } | ||||
174 | |||||
175 | =item delete($) [PUBLIC,ABSTRACT] | ||||
176 | |||||
177 | Usage : my $result = $storage->delete($oid); | ||||
178 | Purpose : Delete the object with given ID from the storage | ||||
179 | Arguments : STRING $oid - unique identifier of the object in storage | ||||
180 | Returns : HASH REFERENCE containing information about the operation result: | ||||
181 | ok => success flag | ||||
182 | n => number of affected items | ||||
183 | err => error flag | ||||
184 | Throws : Dies, if not invoked on instance | ||||
185 | Comments : This operation should always remove only one object | ||||
186 | See Also : For bulk delete operation see remove() method | ||||
187 | |||||
188 | =cut | ||||
189 | |||||
190 | sub delete($) | ||||
191 | { | ||||
192 | my $self = shift; | ||||
193 | confess "Method needs implementation in child class"; | ||||
194 | } | ||||
195 | |||||
196 | =item count(;$) [PUBLIC,ABSTRACT] | ||||
197 | |||||
198 | Usage : my $count = $storage->count(); or | ||||
199 | my $count = $storage->count($filter); | ||||
200 | Purpose : Get the number of Mentat messages in storage | ||||
201 | Arguments : HASH REFERENCE $filter - Query filter [OPTIONAL] | ||||
202 | Returns : INTEGER on SUCCESS | ||||
203 | Throws : Dies, if not invoked on instance | ||||
204 | Dies on operation failure | ||||
205 | |||||
206 | =cut | ||||
207 | |||||
208 | sub count(;$) | ||||
209 | { | ||||
210 | my $self = shift; | ||||
211 | confess "Method needs implementation in child class"; | ||||
212 | } | ||||
213 | |||||
214 | =item find(;$$$$$) [PUBLIC,ABSTRACT] | ||||
215 | |||||
216 | Usage : my ($objects, $count) = $storage->find(); or | ||||
217 | my ($objects, $count) = $storage->find($filter); | ||||
218 | Purpose : Find the object(s) according to the given filter | ||||
219 | Arguments : HASH REFERENCE $filter - Query filter [OPTIONAL] | ||||
220 | HASH REFERENCE $selection - Record attribute selection [OPTIONAL] | ||||
221 | HASH REFERENCE $sort - Sorting specification [OPTIONAL] | ||||
222 | INTEGER $limit - Maximum number of records to be returned [OPTIONAL] | ||||
223 | INTEGER $skip - Number of objects to skip from the beginning of the result set [OPTIONAL] | ||||
224 | Returns : ARRAY REFERENCE containing objects | ||||
225 | INTEGER total count of objects | ||||
226 | Throws : Dies, if not invoked on instance | ||||
227 | |||||
228 | =cut | ||||
229 | |||||
230 | sub find(;$$$$$) | ||||
231 | { | ||||
232 | my $self = shift; | ||||
233 | confess "Method needs implementation in child class"; | ||||
234 | } | ||||
235 | |||||
236 | =item remove(;$) [PUBLIC,ABSTRACT] | ||||
237 | |||||
238 | Usage : my $result = $storage->remove(); or | ||||
239 | my $result = $storage->remove($filter); | ||||
240 | Purpose : Remove the objects(s) according to the given filter | ||||
241 | Arguments : HASH REFERENCE $filter - Filter for selecting items to be removed [OPTIONAL] | ||||
242 | Returns : HASH REFERENCE containing information about the operation result: | ||||
243 | ok => success flag | ||||
244 | n => number of affected items | ||||
245 | err => error flag | ||||
246 | Throws : Dies, if not invoked on instance | ||||
247 | Croaks on query failure | ||||
248 | Comments : This operation performs bulk delete operation | ||||
249 | See Also : For single delete operation see delete() method | ||||
250 | Warning : DELETES ALL DATA, IF GIVEN NO FILTER !!! | ||||
251 | |||||
252 | =cut | ||||
253 | |||||
254 | sub remove(;$) | ||||
255 | { | ||||
256 | my $self = shift; | ||||
257 | confess "Method needs implementation in child class"; | ||||
258 | } | ||||
259 | |||||
260 | =item disconnect() [PUBLIC,ABSTRACT] | ||||
261 | |||||
262 | Usage : $storage->disconnect(); | ||||
263 | Purpose : Close existing storage connection | ||||
264 | Arguments : NONE | ||||
265 | Returns : UNDEF on SUCCESS, STRING $error on FAILURE | ||||
266 | Throws : Dies, if not invoked on instance | ||||
267 | |||||
268 | =cut | ||||
269 | |||||
270 | sub disconnect() | ||||
271 | { | ||||
272 | my $self = shift; | ||||
273 | confess "Method needs implementation in child class"; | ||||
274 | } | ||||
275 | |||||
276 | =item reconnect() [PUBLIC,ABSTRACT] | ||||
277 | |||||
278 | Usage : $storage->reconnect(); | ||||
279 | Purpose : Optionally close existing storage connection and reopen it | ||||
280 | Arguments : NONE | ||||
281 | Returns : UNDEF on SUCCESS, STRING $error on FAILURE | ||||
282 | Throws : Dies, if not invoked on instance | ||||
283 | |||||
284 | =cut | ||||
285 | |||||
286 | sub reconnect() | ||||
287 | { | ||||
288 | my $self = shift; | ||||
289 | confess "Method needs implementation in child class"; | ||||
290 | } | ||||
291 | |||||
292 | #------------------------------------------------------------------------------- | ||||
293 | |||||
294 | # _init [PROTECTED] | ||||
295 | # | ||||
296 | # Usage : | ||||
297 | # Purpose : | ||||
298 | # Arguments : | ||||
299 | # Returns : | ||||
300 | # Throws : Dies, if not invoked on instance | ||||
301 | # Comments : | ||||
302 | # See Also : | ||||
303 | |||||
304 | sub _init | ||||
305 | { | ||||
306 | my $self = shift; | ||||
307 | confess "Method needs implementation in child class"; | ||||
308 | } | ||||
309 | |||||
310 | =pod | ||||
311 | |||||
312 | =back | ||||
313 | |||||
314 | =cut | ||||
315 | |||||
316 | 1 | 2µs | 1; |