1 |
dpavlin |
225 |
package CWMP::Store::JSON; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use CWMP::Store::HASH; |
7 |
|
|
use base qw/CWMP::Store::HASH/; |
8 |
|
|
|
9 |
|
|
use JSON::XS; |
10 |
|
|
use File::Slurp; |
11 |
|
|
|
12 |
|
|
=head1 NAME |
13 |
|
|
|
14 |
|
|
CWMP::Store::YAML - use YAML as storage |
15 |
|
|
|
16 |
|
|
=cut |
17 |
|
|
|
18 |
|
|
my $full_path; |
19 |
|
|
|
20 |
|
|
sub full_path { |
21 |
|
|
my ( $self, $path ) = @_; |
22 |
|
|
$full_path = "$path/json"; |
23 |
dpavlin |
229 |
warn "## full_path: $full_path" if $debug; |
24 |
dpavlin |
225 |
return $full_path; |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
sub file { |
28 |
|
|
my ( $self, $uid ) = @_; |
29 |
|
|
my $file = "$full_path/$uid" . $self->extension; |
30 |
dpavlin |
229 |
warn "## file -> $file" if $debug; |
31 |
dpavlin |
225 |
return $file; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
sub save_hash { |
35 |
|
|
my ( $self, $file, $hash ) = @_; |
36 |
|
|
write_file( $file, to_json $hash ); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
sub load_hash { |
40 |
|
|
my ( $self, $file ) = @_; |
41 |
|
|
from_json read_file( $file ); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
sub extension { '.js' }; |
45 |
|
|
|
46 |
|
|
1; |