| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package HTTP::Session::Store::DBM; | 
| 2 | 2 |  |  | 2 |  | 24064 | use strict; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 84 |  | 
| 3 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 62 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use base qw/Class::Accessor::Fast/; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 192 |  | 
| 5 | 2 |  |  | 2 |  | 14 | use Fcntl; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 909 |  | 
| 6 | 2 |  |  | 2 |  | 2520 | use Storable; | 
|  | 2 |  |  |  |  | 7411 |  | 
|  | 2 |  |  |  |  | 146 |  | 
| 7 | 2 |  |  | 2 |  | 16 | use Module::Runtime (); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 949 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | __PACKAGE__->mk_ro_accessors(qw/file dbm_class/); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub new { | 
| 12 | 4 |  |  | 4 | 1 | 918 | my $class = shift; | 
| 13 | 4 | 50 |  |  |  | 25 | my %args = ref($_[0]) ? %{$_[0]} : @_; | 
|  | 0 |  |  |  |  | 0 |  | 
| 14 |  |  |  |  |  |  | # check required parameters | 
| 15 | 4 |  |  |  |  | 10 | for (qw/file/) { | 
| 16 | 4 | 50 |  |  |  | 21 | Carp::croak "missing parameter $_" unless $args{$_}; | 
| 17 |  |  |  |  |  |  | } | 
| 18 |  |  |  |  |  |  | # set default values | 
| 19 | 4 |  | 100 |  |  | 28 | $args{dbm_class} ||= 'SDBM_File'; | 
| 20 | 4 |  |  |  |  | 56 | bless {%args}, $class; | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub dbm { | 
| 24 | 6 |  |  | 6 | 0 | 244 | my $self = shift; | 
| 25 | 6 |  | 66 |  |  | 184 | $self->{dbm} ||= do { | 
| 26 | 4 |  |  |  |  | 7 | my %hash; | 
| 27 | 4 | 50 |  |  |  | 18 | Module::Runtime::require_module($self->dbm_class) or die $@; | 
| 28 | 4 | 50 |  |  |  | 7578 | tie %hash, $self->dbm_class, $self->file, O_CREAT | O_RDWR, oct("600") or die "Cannot open dbm file for session: $self->{dbm_class}, $self->{file}"; | 
| 29 | 4 |  |  |  |  | 864 | \%hash; | 
| 30 |  |  |  |  |  |  | }; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub select { | 
| 34 | 4 |  |  | 4 | 1 | 31 | my ( $self, $key ) = @_; | 
| 35 | 4 |  |  |  |  | 14 | Storable::thaw $self->dbm->{$key}; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub insert { | 
| 39 | 2 |  |  | 2 | 1 | 23 | my ( $self, $key, $value ) = @_; | 
| 40 | 2 |  |  |  |  | 11 | $self->dbm->{$key} = Storable::freeze $value; | 
| 41 |  |  |  |  |  |  | } | 
| 42 | 0 |  |  | 0 | 1 |  | sub update { shift->insert(@_) } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub delete { | 
| 45 | 0 |  |  | 0 | 1 |  | my ( $self, $key ) = @_; | 
| 46 | 0 |  |  |  |  |  | delete $self->dbm->{$key}; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 |  |  | 0 | 0 |  | sub cleanup { Carp::croak "This storage doesn't support cleanup" } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | 1; | 
| 52 |  |  |  |  |  |  | __END__ |