… | |
… | |
20 | use Coro::Signal; |
20 | use Coro::Signal; |
21 | use Coro::Semaphore; |
21 | use Coro::Semaphore; |
22 | use Coro::AIO; |
22 | use Coro::AIO; |
23 | use Coro::Storable; |
23 | use Coro::Storable; |
24 | |
24 | |
|
|
25 | use JSON::XS 1.4 (); |
25 | use BDB (); |
26 | use BDB (); |
26 | use Data::Dumper; |
27 | use Data::Dumper; |
27 | use Digest::MD5; |
28 | use Digest::MD5; |
28 | use Fcntl; |
29 | use Fcntl; |
29 | use YAML::Syck (); |
30 | use YAML::Syck (); |
… | |
… | |
237 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
238 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
238 | $d |
239 | $d |
239 | } || "[unable to dump $_[0]: '$@']"; |
240 | } || "[unable to dump $_[0]: '$@']"; |
240 | } |
241 | } |
241 | |
242 | |
242 | use JSON::XS (); |
|
|
243 | |
|
|
244 | =item $ref = cf::from_json $json |
243 | =item $ref = cf::from_json $json |
245 | |
244 | |
246 | Converts a JSON string into the corresponding perl data structure. |
245 | Converts a JSON string into the corresponding perl data structure. |
247 | |
246 | |
248 | =item $json = cf::to_json $ref |
247 | =item $json = cf::to_json $ref |
249 | |
248 | |
250 | Converts a perl data structure into its JSON representation. |
249 | Converts a perl data structure into its JSON representation. |
251 | |
250 | |
252 | =cut |
251 | =cut |
253 | |
252 | |
254 | our $json_coder = JSON::XS->new->convert_blessed->utf8; |
253 | our $json_coder = JSON::XS->new->convert_blessed->utf8->max_size (1e6); # accept ~1mb max |
255 | |
254 | |
256 | sub to_json ($) { $json_coder->encode ($_[0]) } |
255 | sub to_json ($) { $json_coder->encode ($_[0]) } |
257 | sub from_json ($) { $json_coder->decode ($_[0]) } |
256 | sub from_json ($) { $json_coder->decode ($_[0]) } |
258 | |
257 | |
259 | =item cf::lock_wait $string |
258 | =item cf::lock_wait $string |