| File | /usr/share/perl5/CGI/Session/Driver.pm | Statements Executed | 17 | Total Time | 0.000386 seconds |
| Calls | Inclusive Time | Subroutine | |
|---|---|---|---|
| 1 | 0.00006 | CGI::Session::Driver:: | new |
| 0 | 0 | CGI::Session::Driver:: | BEGIN |
| 0 | 0 | CGI::Session::Driver:: | dump |
| 0 | 0 | CGI::Session::Driver:: | init |
| 0 | 0 | CGI::Session::Driver:: | remove |
| 0 | 0 | CGI::Session::Driver:: | retrieve |
| 0 | 0 | CGI::Session::Driver:: | store |
| 0 | 0 | CGI::Session::Driver:: | traverse |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package CGI::Session::Driver; | |||
| 2 | ||||
| 3 | # $Id: Driver.pm 351 2006-11-24 14:16:50Z markstos $ | |||
| 4 | ||||
| 5 | 3 | 0.00003 | 8e-06 | use strict; # spent 0.00001s making 1 calls to strict::import |
| 6 | #use diagnostics; | |||
| 7 | ||||
| 8 | 3 | 0.00003 | 0.00001 | use Carp; # spent 0.00006s making 1 calls to Exporter::import |
| 9 | 3 | 0.00030 | 0.00010 | use CGI::Session::ErrorHandler; # spent 5e-06s making 1 calls to 1 |
| 10 | ||||
| 11 | 1 | 1e-06 | 1e-06 | $CGI::Session::Driver::VERSION = "4.20"; |
| 12 | 1 | 2e-06 | 2e-06 | @CGI::Session::Driver::ISA = qw(CGI::Session::ErrorHandler); |
| 13 | ||||
| 14 | # spent 0.00006s within CGI::Session::Driver::new which was called:
# 1 times (0.00006s) by CGI::Session::_driver at line 113 of /usr/share/perl5/CGI/Session.pm sub new { | |||
| 15 | 5 | 0.00002 | 4e-06 | 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 | # perform a shallow copy of $args, to prevent modification | |||
| 23 | my $self = bless ({%$args}, $class); | |||
| 24 | return $self if $self->init(); # spent 0.00003s making 1 calls to CGI::Session::Driver::mysql::init | |||
| 25 | return $self->set_error( "%s->init() returned false", $class); | |||
| 26 | } | |||
| 27 | ||||
| 28 | sub init { 1 } | |||
| 29 | ||||
| 30 | sub retrieve { | |||
| 31 | croak "retrieve(): " . ref($_[0]) . " failed to implement this method!"; | |||
| 32 | } | |||
| 33 | ||||
| 34 | sub store { | |||
| 35 | croak "store(): " . ref($_[0]) . " failed to implement this method!"; | |||
| 36 | } | |||
| 37 | ||||
| 38 | sub remove { | |||
| 39 | croak "remove(): " . ref($_[0]) . " failed to implement this method!"; | |||
| 40 | } | |||
| 41 | ||||
| 42 | sub traverse { | |||
| 43 | croak "traverse(): " . ref($_[0]) . " failed to implement this method!"; | |||
| 44 | } | |||
| 45 | ||||
| 46 | sub dump { | |||
| 47 | require Data::Dumper; | |||
| 48 | my $d = Data::Dumper->new([$_[0]], [ref $_[0]]); | |||
| 49 | return $d->Dump; | |||
| 50 | } | |||
| 51 | ||||
| 52 | ||||
| 53 | 1 | 4e-06 | 4e-06 | 1; |
| 54 | ||||
| 55 | __END__; | |||
| 56 | ||||
| 57 | =pod | |||
| 58 | ||||
| 59 | =head1 NAME | |||
| 60 | ||||
| 61 | CGI::Session::Driver - CGI::Session driver specifications | |||
| 62 | ||||
| 63 | =head1 WARNING | |||
| 64 | ||||
| 65 | Version 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. | |||
| 66 | ||||
| 67 | If you need any help converting your driver to meet current specs, send me an e-mail. For support information see | |||
| 68 | L<CGI::Session|CGI::Session> | |||
| 69 | ||||
| 70 | =head1 SYNOPSIS | |||
| 71 | ||||
| 72 | require CGI::Session::Driver; | |||
| 73 | @ISA = qw( CGI::Session::Driver ); | |||
| 74 | ||||
| 75 | =head1 DESCRIPTION | |||
| 76 | ||||
| 77 | CGI::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. | |||
| 78 | ||||
| 79 | =head1 WHAT IS A DRIVER | |||
| 80 | ||||
| 81 | Driver 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. | |||
| 82 | ||||
| 83 | =head2 BLUEPRINT | |||
| 84 | ||||
| 85 | The best way of learning the specs is to look at a blueprint of a driver: | |||
| 86 | ||||
| 87 | package CGI::Session::Driver::your_driver_name; | |||
| 88 | use strict; | |||
| 89 | use base qw( CGI::Session::Driver CGI::Session::ErrorHandler ); | |||
| 90 | ||||
| 91 | sub init { | |||
| 92 | my ($self) = @_; | |||
| 93 | # optional | |||
| 94 | } | |||
| 95 | ||||
| 96 | sub DESTROY { | |||
| 97 | my ($self) = @_; | |||
| 98 | # optional | |||
| 99 | } | |||
| 100 | ||||
| 101 | sub store { | |||
| 102 | my ($self, $sid, $datastr) = @_; | |||
| 103 | # Store $datastr, which is an already serialized string of data. | |||
| 104 | } | |||
| 105 | ||||
| 106 | sub retrieve { | |||
| 107 | my ($self, $sid) = @_; | |||
| 108 | # Return $datastr, which was previously stored using above store() method. | |||
| 109 | # Return $datastr if $sid was found. Return 0 or "" if $sid doesn't exist | |||
| 110 | } | |||
| 111 | ||||
| 112 | sub remove { | |||
| 113 | my ($self, $sid) = @_; | |||
| 114 | # Remove storage associated with $sid. Return any true value indicating success, | |||
| 115 | # or undef on failure. | |||
| 116 | } | |||
| 117 | ||||
| 118 | sub traverse { | |||
| 119 | my ($self, $coderef) = @_; | |||
| 120 | # execute $coderef for each session id passing session id as the first and the only | |||
| 121 | # argument | |||
| 122 | } | |||
| 123 | ||||
| 124 | 1; | |||
| 125 | ||||
| 126 | All the attributes passed as the second argument to CGI::Session's new() or load() methods will automatically | |||
| 127 | be made driver's object attributes. For example, if session object was initialized as following: | |||
| 128 | ||||
| 129 | $s = CGI::Session->new("driver:your_driver_name", undef, {Directory=>'/tmp/sessions'}); | |||
| 130 | ||||
| 131 | You can access value of 'Directory' from within your driver like so: | |||
| 132 | ||||
| 133 | sub store { | |||
| 134 | my ($self, $sid, $datastr) = @_; | |||
| 135 | my $dir = $self->{Directory}; # <-- in this example will be '/tmp/sessions' | |||
| 136 | } | |||
| 137 | ||||
| 138 | Optionally, 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. | |||
| 139 | ||||
| 140 | For examples of C<init()> look into the source code of native CGI::Session drivers. | |||
| 141 | ||||
| 142 | =head1 METHODS | |||
| 143 | ||||
| 144 | This 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. | |||
| 145 | ||||
| 146 | Following 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. | |||
| 147 | ||||
| 148 | =over 4 | |||
| 149 | ||||
| 150 | =item retrieve($self, $sid) | |||
| 151 | ||||
| 152 | Called 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>. | |||
| 153 | ||||
| 154 | Tip: set_error() always returns undef. Use it for your advantage. | |||
| 155 | ||||
| 156 | =item store($self, $sid, $datastr) | |||
| 157 | ||||
| 158 | Called 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. | |||
| 159 | ||||
| 160 | C< 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. | |||
| 161 | ||||
| 162 | $datastr, which is passed as the third argument to represents B<already serialized> session data that needs to be saved. | |||
| 163 | ||||
| 164 | store() can return any true value indicating success or undef on failure. Error message should be passed to set_error() | |||
| 165 | ||||
| 166 | =item remove($self, $sid) | |||
| 167 | ||||
| 168 | Called 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(). | |||
| 169 | ||||
| 170 | =item traverse($self, \&coderef) | |||
| 171 | ||||
| 172 | Called 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 ) >> | |||
| 173 | ||||
| 174 | =item init($self) | |||
| 175 | ||||
| 176 | Optional. 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. | |||
| 177 | ||||
| 178 | =item DESTROY($self) | |||
| 179 | ||||
| 180 | Optional. 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. | |||
| 181 | ||||
| 182 | =back | |||
| 183 | ||||
| 184 | =head2 NOTES | |||
| 185 | ||||
| 186 | =over 4 | |||
| 187 | ||||
| 188 | =item * | |||
| 189 | ||||
| 190 | All driver F<.pm> files must be lowercase! | |||
| 191 | ||||
| 192 | =item * | |||
| 193 | ||||
| 194 | DBI-related drivers are better off using L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI> as base, but don't have to. | |||
| 195 | ||||
| 196 | =back | |||
| 197 | ||||
| 198 | =head1 LICENSING | |||
| 199 | ||||
| 200 | For support and licensing see L<CGI::Session|CGI::Session>. | |||
| 201 | ||||
| 202 | =cut |