1 |
# Dobrica Pavlinusic, <dpavlin@rot13.org> 06/22/07 14:35:38 CEST |
2 |
package CWMP::Store; |
3 |
|
4 |
use strict; |
5 |
use warnings; |
6 |
|
7 |
|
8 |
use base qw/Class::Accessor/; |
9 |
__PACKAGE__->mk_accessors( qw/ |
10 |
debug |
11 |
path |
12 |
|
13 |
db |
14 |
/ ); |
15 |
|
16 |
use Carp qw/confess/; |
17 |
use Data::Dump qw/dump/; |
18 |
use DBM::Deep; |
19 |
|
20 |
=head1 NAME |
21 |
|
22 |
CWMP::Store - parsist CPE state on disk |
23 |
|
24 |
=head1 METHODS |
25 |
|
26 |
=head2 new |
27 |
|
28 |
my $store = CWMP::Store->new({ |
29 |
path => '/path/to/state.db', |
30 |
debug => 1, |
31 |
}); |
32 |
|
33 |
=cut |
34 |
|
35 |
sub new { |
36 |
my $class = shift; |
37 |
my $self = $class->SUPER::new( @_ ); |
38 |
|
39 |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug; |
40 |
|
41 |
$self->db( |
42 |
DBM::Deep->new( |
43 |
file => $self->path, |
44 |
locking => 1, |
45 |
autoflush => 1, |
46 |
) |
47 |
); |
48 |
|
49 |
return $self; |
50 |
} |
51 |
|
52 |
=head2 update_state |
53 |
|
54 |
$store->update_state( $ID, $state ); |
55 |
|
56 |
=cut |
57 |
|
58 |
sub update_state { |
59 |
my $self = shift; |
60 |
|
61 |
my ( $ID, $state ) = @_; |
62 |
|
63 |
confess "need ID" unless $ID; |
64 |
confess "need state" unless $state; |
65 |
|
66 |
warn "## update state of $ID\n" if $self->debug; |
67 |
|
68 |
$self->db->import( $ID => $state ); |
69 |
} |
70 |
1; |