38 |
|
|
39 |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug; |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug; |
40 |
|
|
41 |
|
confess "need path to state.db" unless ( $self->path ); |
42 |
|
|
43 |
$self->db( |
$self->db( |
44 |
DBM::Deep->new( |
DBM::Deep->new( |
45 |
file => $self->path, |
file => $self->path, |
65 |
confess "need ID" unless $ID; |
confess "need ID" unless $ID; |
66 |
confess "need state" unless $state; |
confess "need state" unless $state; |
67 |
|
|
68 |
warn "## update state of $ID\n" if $self->debug; |
if ( my $o = $self->db->get( $ID ) ) { |
69 |
|
warn "## update state of $ID\n" if $self->debug; |
70 |
|
$o->import( $state ); |
71 |
|
} else { |
72 |
|
warn "## create new state for $ID\n" if $self->debug; |
73 |
|
$self->db->put( $ID => $state ); |
74 |
|
} |
75 |
|
|
76 |
|
} |
77 |
|
|
78 |
|
=head2 state |
79 |
|
|
80 |
|
my $state = $store->state( $ID ); |
81 |
|
|
82 |
|
Returns normal unblessed hash (actually, in-memory copy of state in database). |
83 |
|
|
84 |
$self->db->import( $ID => $state ); |
=cut |
85 |
|
|
86 |
|
sub state { |
87 |
|
my $self = shift; |
88 |
|
my ( $ID ) = @_; |
89 |
|
confess "need ID" unless $ID; |
90 |
|
return $self->db->get( $ID )->export; |
91 |
} |
} |
92 |
|
|
93 |
1; |
1; |