#========================================================================
#
# Badger::Codec::JSON
#
# DESCRIPTION
# Codec module for encoding/decoding Base64
#
# AUTHOR
# Andy Wardley <abw@wardl
ge Badger::Codec::JSON;
use Badger::Class
version => 0.01,
base => 'Badger::Codec',
import => 'class',
codecs => 'utf8';
eval "require JSON::XS";
our $HAS_JSON_XS = $@ ? 0 : 1;
eval "require JSON";
our $HAS_JSON = $@ ? 0 : 1;
our $MODULE =
$HAS_JSON_XS ? 'JSON::XS' :
$HAS_JSON ? 'JSON' :
die "No JSON implementation installed\n";
# TODO: figure out if it
extensions quiet',
words => 'ENCODING CODECS',
constants => 'DOT NONE TRUE FALSE YAML JSON UTF8 ARRAY HASH SCALAR',
constant => {
ABSOLUTE => 'absolute',
RELATIVE => '
merge_mismatch => 'Cannot merge items for %s: %s and %s',
};
our $EXTENSIONS = [YAML, JSON];
our $ENCODING = UTF8;
our $CODECS = { };
our $STAT_TTL = 0;
#------------------------
# Configuration files can be in any data format which Badger::Codecs can
# handle (e.g. JSON, YAML, etc). The 'extensions' configuration option
# and any $EXTENSIONS defined in package
',
url => 'Badger::Codec::URL',
yaml => 'Badger::Codec::YAML',
json => 'Badger::Codec::JSON',
html => 'Badger::Codec::HTML',
tt => 'Badger::Codec::TT',
m
ows options to default to
the values set by preceeding options.
Changed L<Badger::Codec::JSON> to use L<JSON::XS> if available.
Mr T is now using Badger 0.06 in production code and is happy to repo
ault
codec for a directory or filesystem.
$directory->codec('json');
$file = $directory->file('foo.json'); # has json codec set
=head1 AUTHOR
Andy Wardley L<http://wardley.org/>
=he
o install YAML or JSON just to run some of the Badger
tests) and to support some legacy systems that use data encoded in this way
(mostly dating back to the days before YAML and JSON were around). If
you're
starting out afresh then you're probably better off using YAML or JSON unless
you have good reason not to.
The syntax is similar to Perl in that it uses single quotes for literal
strings, squa
:> as a delimiter between hash keys and values,
thus providing an overlap with a useful subset of JSON syntax:
{
message: 'Hello World, this is some text',
things: ['a list' 'of s
ecs are for encoding and decoding data between all sorts of different
formats: Unicode, Base 64, JSON, YAML, Storable, and so on. Codecs are
simple wrappers around existing modules that make it tri