/[cwmp]/google/lib/CWMP/Store.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /google/lib/CWMP/Store.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 85 - (hide annotations)
Fri Jun 22 18:36:09 2007 UTC (17 years ago) by dpavlin
File size: 1444 byte(s)
Implemented store->state( $ID ) and use it to test server
1 dpavlin 77 # 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 dpavlin 79 db
14 dpavlin 77 / );
15    
16 dpavlin 79 use Carp qw/confess/;
17 dpavlin 77 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 dpavlin 84 confess "need path to state.db" unless ( $self->path );
42    
43 dpavlin 79 $self->db(
44 dpavlin 77 DBM::Deep->new(
45     file => $self->path,
46     locking => 1,
47     autoflush => 1,
48     )
49     );
50    
51     return $self;
52     }
53    
54 dpavlin 79 =head2 update_state
55 dpavlin 77
56 dpavlin 79 $store->update_state( $ID, $state );
57    
58     =cut
59    
60     sub update_state {
61     my $self = shift;
62    
63     my ( $ID, $state ) = @_;
64    
65     confess "need ID" unless $ID;
66     confess "need state" unless $state;
67    
68 dpavlin 81 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 dpavlin 79 }
77 dpavlin 85
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     =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 dpavlin 77 1;

  ViewVC Help
Powered by ViewVC 1.1.26