← Index
Performance Profile   « block view • line view • sub view »
For /home/chris/git/koha.git/cataloguing/addbiblio.pl
  Run on Tue Aug 25 11:37:23 2009
Reported on Tue Aug 25 11:37:50 2009

File /usr/share/perl5/CGI/Session/Driver.pm
Statements Executed 20
Total Time 0.0005976 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11136µs94µsCGI::Session::Driver::::newCGI::Session::Driver::new
0000s0sCGI::Session::Driver::::BEGINCGI::Session::Driver::BEGIN
0000s0sCGI::Session::Driver::::dumpCGI::Session::Driver::dump
0000s0sCGI::Session::Driver::::initCGI::Session::Driver::init
0000s0sCGI::Session::Driver::::removeCGI::Session::Driver::remove
0000s0sCGI::Session::Driver::::retrieveCGI::Session::Driver::retrieve
0000s0sCGI::Session::Driver::::storeCGI::Session::Driver::store
0000s0sCGI::Session::Driver::::traverseCGI::Session::Driver::traverse
LineStmts.Exclusive
Time
Avg.Code
1package CGI::Session::Driver;
2
3# $Id: Driver.pm 447 2008-11-01 03:46:08Z markstos $
4
5239µs20µsuse strict;
# spent 14µs making 1 call to strict::import
6#use diagnostics;
7
8343µs14µsuse Carp;
# spent 64µs making 1 call to Exporter::import
94462µs116µsuse CGI::Session::ErrorHandler;
# spent 248µs making 1 call to UNIVERSAL::import
10
111900ns900ns$CGI::Session::Driver::VERSION = '4.38';
1219µs9µs@CGI::Session::Driver::ISA = qw(CGI::Session::ErrorHandler);
13
14
# spent 94µs (36+58) within CGI::Session::Driver::new which was called # once (36µs+58µs) by CGI::Session::_driver at line 120 of /usr/share/perl5/CGI/Session.pm
sub new {
15837µs5µs my $class = shift;
16 my $args = shift || {};
17
18 unless ( ref $args ) {
19 croak "$class->new(): Invalid argument type passed to driver";
20 }
21
22 # Set defaults.
23
24 if (! $args->{TableName}) {
25 $args->{TableName} = 'sessions';
26 }
27
28 if (! $args->{IdColName}) {
29 $args->{IdColName} = 'id';
30 }
31
32 if (! $args->{DataColName}) {
33 $args->{DataColName} = 'a_session';
34 }
35
36 # perform a shallow copy of $args, to prevent modification
37 my $self = bless ({%$args}, $class);
38 return $self if $self->init();
# spent 57µs making 1 call to CGI::Session::Driver::mysql::init
39 return $self->set_error( "%s->init() returned false", $class);
40}
41
42sub init { 1 }
43
44sub retrieve {
45 croak "retrieve(): " . ref($_[0]) . " failed to implement this method!";
46}
47
48sub store {
49 croak "store(): " . ref($_[0]) . " failed to implement this method!";
50}
51
52sub remove {
53 croak "remove(): " . ref($_[0]) . " failed to implement this method!";
54}
55
56sub traverse {
57 croak "traverse(): " . ref($_[0]) . " failed to implement this method!";
58}
59
60sub dump {
61 require Data::Dumper;
62 my $d = Data::Dumper->new([$_[0]], [ref $_[0]]);
63 return $d->Dump;
64}
65
66
6715µs5µs1;
68
69__END__;
70
71=pod
72
73=head1 NAME
74
75CGI::Session::Driver - CGI::Session driver specifications
76
77=head1 WARNING
78
79Version 4.0 of CGI::Session's driver specification is B<NOT> backward compatible with previous specification. If you already have a driver developed to work with the previous version you're highly encouraged to upgrade your driver code to make it compatible with the current version. Fortunately, current driver specs are a lot easier to adapt to.
80
81If you need any help converting your driver to meet current specs, send me an e-mail. For support information see
82L<CGI::Session|CGI::Session>
83
84=head1 SYNOPSIS
85
86 require CGI::Session::Driver;
87 @ISA = qw( CGI::Session::Driver );
88
89=head1 DESCRIPTION
90
91CGI::Session::Driver is a base class for all CGI::Session's native drivers. It also documents driver specifications for those willing to write drivers for different databases not currently supported by CGI::Session.
92
93=head1 WHAT IS A DRIVER
94
95Driver is a piece of code that helps CGI::Session library to talk to specific database engines, or storage mechanisms. To be more precise, driver is a F<.pm> file that inherits from CGI::Session::Driver and defines L<retrieve()|/"retrieve($self, $sid)">, L<store()|/"store($self, $sid, $datastr)"> and L<remove()|/"remove($self, $sid)"> methods.
96
97=head2 BLUEPRINT
98
99The best way of learning the specs is to look at a blueprint of a driver:
100
101 package CGI::Session::Driver::your_driver_name;
102 use strict;
103 use base qw( CGI::Session::Driver CGI::Session::ErrorHandler );
104
105 sub init {
106 my ($self) = @_;
107 # optional
108 }
109
110 sub DESTROY {
111 my ($self) = @_;
112 # optional
113 }
114
115 sub store {
116 my ($self, $sid, $datastr) = @_;
117 # Store $datastr, which is an already serialized string of data.
118 }
119
120 sub retrieve {
121 my ($self, $sid) = @_;
122 # Return $datastr, which was previously stored using above store() method.
123 # Return $datastr if $sid was found. Return 0 or "" if $sid doesn't exist
124 }
125
126 sub remove {
127 my ($self, $sid) = @_;
128 # Remove storage associated with $sid. Return any true value indicating success,
129 # or undef on failure.
130 }
131
132 sub traverse {
133 my ($self, $coderef) = @_;
134 # execute $coderef for each session id passing session id as the first and the only
135 # argument
136 }
137
138 1;
139
140All the attributes passed as the second argument to CGI::Session's new() or load() methods will automatically
141be made driver's object attributes. For example, if session object was initialized as following:
142
143 $s = CGI::Session->new("driver:your_driver_name", undef, {Directory=>'/tmp/sessions'});
144
145You can access value of 'Directory' from within your driver like so:
146
147 sub store {
148 my ($self, $sid, $datastr) = @_;
149 my $dir = $self->{Directory}; # <-- in this example will be '/tmp/sessions'
150 }
151
152Optionally, you can define C<init()> method within your driver to do driver specific global initialization. C<init()> method will be invoked only once during the lifecycle of your driver, which is the same as the lifecycle of a session object.
153
154For examples of C<init()> look into the source code of native CGI::Session drivers.
155
156=head1 METHODS
157
158This section lists and describes all driver methods. All the driver methods will receive driver object ($self) as the first argument. Methods that pertain to an individual session (such as C<retrieve()>, C<store()> and C<remove()>) will also receive session id ($sid) as the second argument.
159
160Following list describes every driver method, including its argument list and what step of session's life they will be invoked. Understanding this may help driver authors.
161
162=over 4
163
164=item retrieve($self, $sid)
165
166Called whenever a specific session is requested either via C<< CGI::Session->new() >> or C<< CGI::Session->load() >> syntax. Method should try to retrieve data associated with C< $sid > and return it. In case no data could be retrieved for C< $sid > 0 (zero) or "" should be returned. undef must be returned only to signal error. Error message should be set via set_error(), which can be inherited from L<CGI::Session::ErrorHandler|CGI::Session::ErrorHandler>.
167
168Tip: set_error() always returns undef. Use it for your advantage.
169
170=item store($self, $sid, $datastr)
171
172Called whenever modified session data is to be stored back to disk. This happens whenever CGI::Session->flush() is called on modified session. Since CGI::Session->DESTROY() calls flush(), store() gets requested each time session object is to be terminated.
173
174C< store() > is called both to store new sessions and to update already stored sessions. It's driver author's job to figure out which operation needs to be performed.
175
176$datastr, which is passed as the third argument to represents B<already serialized> session data that needs to be saved.
177
178store() can return any true value indicating success or undef on failure. Error message should be passed to set_error()
179
180=item remove($self, $sid)
181
182Called whenever session data is to be deleted, which is when CGI::Session->delete() is called. Should return any true value indicating success, undef on failure. Error message should be logged in set_error().
183
184=item traverse($self, \&coderef)
185
186Called only from within CGI::Session->find(). Job of traverse() is to call \&coderef for every single session stored in disk passing session's id as the first and only argument: C<< $coderef->( $sid ) >>
187
188=item init($self)
189
190Optional. Called whenever driver object is to be initialized, which happens only once during the lifecycle of CGI::Session object. Here you can do driver-wide initialization, such as to open connection to a database server.
191
192=item DESTROY($self)
193
194Optional. Perl automatically calls this method on objects just before they are to be terminated. This gives your driver chance to close any database connections or close any open file handles.
195
196=back
197
198=head2 NOTES
199
200=over 4
201
202=item *
203
204All driver F<.pm> files must be lowercase!
205
206=item *
207
208DBI-related drivers are better off using L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI> as base, but don't have to.
209
210=back
211
212=head1 LICENSING
213
214For support and licensing see L<CGI::Session|CGI::Session>.
215
216=cut