27 |
my $store = CWMP::Store->new({ |
my $store = CWMP::Store->new({ |
28 |
module => 'DBMDeep', |
module => 'DBMDeep', |
29 |
path => '/path/to/state.db', |
path => '/path/to/state.db', |
30 |
|
clean => 1, |
31 |
debug => 1, |
debug => 1, |
32 |
}); |
}); |
33 |
|
|
39 |
|
|
40 |
confess "requed parametar module is missing" unless $self->module; |
confess "requed parametar module is missing" unless $self->module; |
41 |
|
|
42 |
warn "created ", __PACKAGE__, "(", dump( @_ ), ") object\n" if $self->debug; |
# XXX it's important to call possible_stores once, because current_store won't work |
43 |
|
my @plugins = $self->possible_stores(); |
44 |
|
|
45 |
warn "Found store plugins: ", join(", ", __PACKAGE__->possible_stores() ); |
warn "Found store plugins: ", join(", ", @plugins ), "\n" if $self->debug; |
46 |
|
|
47 |
$self->current_store->open( @_ ); |
$self->current_store->open( @_ ); |
48 |
|
|
63 |
|
|
64 |
confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s; |
confess "unknown store module $module not one of ", dump( $self->possible_stores ) unless $s; |
65 |
|
|
66 |
warn "current store = ",dump( $s ); |
warn "## current store = $s\n" if $self->debug; |
67 |
|
|
68 |
return $s; |
return $s; |
69 |
} |
} |
102 |
$self->current_store->update_uid_state( $uid, $state ); |
$self->current_store->update_uid_state( $uid, $state ); |
103 |
} |
} |
104 |
|
|
105 |
=head2 state |
=head2 get_state |
106 |
|
|
107 |
my $state = $store->state( ID => $ID ); |
my $state = $store->get_state( ID => $ID ); |
108 |
my $state = $store->state( uid => $uid ); |
my $state = $store->get_state( uid => $uid ); |
109 |
|
|
110 |
Returns normal unblessed hash (actually, in-memory copy of state in database). |
Returns normal unblessed hash (actually, in-memory copy of state in database). |
111 |
|
|
112 |
=cut |
=cut |
113 |
|
|
114 |
sub state { |
sub get_state { |
115 |
my $self = shift; |
my $self = shift; |
116 |
my ( $k, $v ) = @_; |
my ( $k, $v ) = @_; |
117 |
confess "need ID or uid" unless $k =~ m/^(ID|uid)$/; |
confess "need ID or uid" unless $k =~ m/^(ID|uid)$/; |
118 |
confess "need $k value" unless $v; |
confess "need $k value" unless $v; |
119 |
|
|
120 |
warn "## state( $k => $v )\n" if $self->debug; |
warn "## get_state( $k => $v )\n" if $self->debug; |
121 |
|
|
122 |
my $uid; |
my $uid; |
123 |
|
|
136 |
|
|
137 |
} |
} |
138 |
|
|
139 |
=head2 known_CPE |
=head2 all_uids |
140 |
|
|
141 |
my @cpe = $store->known_CPE; |
my @cpe = $store->all_uids; |
142 |
|
|
143 |
=cut |
=cut |
144 |
|
|
145 |
sub known_CPE { |
sub all_uids { |
146 |
my $self = shift; |
my $self = shift; |
147 |
my @cpes = $self->current_store->all_uids; |
my @cpes = $self->current_store->all_uids; |
148 |
warn "all CPE: ", dump( @cpes ), "\n" if $self->debug; |
warn "## all_uids = ", dump( @cpes ), "\n" if $self->debug; |
149 |
return @cpes; |
return @cpes; |
150 |
} |
} |
151 |
|
|