line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MLDBM::Serializer::JSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
26072
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
95
|
|
5
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION @ISA); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
104
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1842
|
use JSON::Any; |
|
2
|
|
|
|
|
50953
|
|
|
2
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
MLDBM::Serializer::JSON - DBM serializer uses JSON for language interoperability |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$VERSION = '0.002'; |
16
|
|
|
|
|
|
|
@ISA = qw(MLDBM::Serializer); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# using MLDBM hash interface |
21
|
|
|
|
|
|
|
use MLDBM qw(DB_File JSON); # use Storable for serializing |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my %db; |
24
|
|
|
|
|
|
|
my $dbm = tie %db, 'MLDBM' [ ... other MLDBM args ... ] or die $! |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$db{foo} = 'bar'; |
27
|
|
|
|
|
|
|
$db{more} = 42; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
while( my ($k,$v) = each %db) { |
30
|
|
|
|
|
|
|
print "$k = $v\n"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# or using DBD::DBM ... |
34
|
|
|
|
|
|
|
use DBI; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $dbh = DBI->connect( "dbi:DBM:", undef, undef, { |
37
|
|
|
|
|
|
|
dbm_type = "DB_File", |
38
|
|
|
|
|
|
|
dbm_mldbm = "JSON", |
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
... |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
MLDBM::Serializer::JSON provides an extension to MLDBM to enable storing the |
45
|
|
|
|
|
|
|
additional columns as JSON instead of Data::Dumper or FreezeThaw. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
JSON is very widely used - from Perl over Ruby to Python and surely |
48
|
|
|
|
|
|
|
JavaScript and so on. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 serialize |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
serialize a given array into a json string |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub serialize { |
59
|
4
|
|
|
4
|
1
|
1780
|
return JSON::Any->objToJson([$_[1]]); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 deserialize |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
deserialize a json string into an array for MLDBM |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub deserialize { |
69
|
4
|
|
|
4
|
1
|
2323
|
my ($obj) = JSON::Any->jsonToObj($_[1]); |
70
|
4
|
|
|
|
|
216
|
return $obj->[0]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHOR |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Jens Rehsack, C<< >> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 BUGS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
80
|
|
|
|
|
|
|
C, or through the web interface |
81
|
|
|
|
|
|
|
at L. |
82
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
83
|
|
|
|
|
|
|
on your bug as I make changes. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SUPPORT |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
perldoc MLDBM::Serializer::JSON |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
You can also look for information at: |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * CPAN Ratings |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * Search CPAN |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Copyright 2010 Jens Rehsack. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
118
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
119
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; # End of MLDBM::Serializer::JSON |