… | |
… | |
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 |
… | |
… | |
2711 | } |
2710 | } |
2712 | |
2711 | |
2713 | sub reload_archetypes { |
2712 | sub reload_archetypes { |
2714 | load_resource_file "$DATADIR/archetypes" |
2713 | load_resource_file "$DATADIR/archetypes" |
2715 | or die "unable to load archetypes\n"; |
2714 | or die "unable to load archetypes\n"; |
|
|
2715 | #d# NEED to laod twice to resolve forward references |
|
|
2716 | # this really needs to be done in an extra post-pass |
|
|
2717 | # (which needs to be synchronous, so solve it differently) |
|
|
2718 | load_resource_file "$DATADIR/archetypes" |
|
|
2719 | or die "unable to load archetypes\n"; |
2716 | } |
2720 | } |
2717 | |
2721 | |
2718 | sub reload_treasures { |
2722 | sub reload_treasures { |
2719 | load_resource_file "$DATADIR/treasures" |
2723 | load_resource_file "$DATADIR/treasures" |
2720 | or die "unable to load treasurelists\n"; |
2724 | or die "unable to load treasurelists\n"; |