Load a JSON package and define our decode_json function:
BEGIN
{
if (_eval "use JSON::XS ()") {
# Can't find JSON::XS, try JSON (2.0 or later):
_eval_or_die "use JSON qw(decode_json)";
}
if ($JSON::XS::VERSION >= 2) {
*decode_json = \&JSON::XS::decode_json;
} else {
*decode_json = \&JSON::XS::from_json; # old name for decode_json
} # end else found JSON::XS pri
or to version 2.0
} # end else we were able to load JSON::XS
} # end BEGIN
#=====================================================================
# Define exceptions:
use Exception::Class (
'Web
JSON 2 can substitute for JSON::XS:
sub prereq_failures
{
my $self = shift @_;
my $out = $self->SUPER::prereq_failures(@_);
return $out unless $out;
if (my $attrib = $out->{requires}{'JSON
my $message;
eval "use JSON 2 ();";
if (not $@) {
# JSON 2.0 or later is an acceptable replacement for JSON::XS:
delete $out->{requires}{'JSON::XS'};
# Clean out empty
JSON 2.0 or later can substitute for JSON::XS, but its pure-Perl
implementation is slower, and you don't have it installed either.
} # end else we couldn't load JSON 2 either
} # end if JSON
===============
BEGIN {
__PACKAGE__->_define(
type => 'member',
ro => [qw(accounts:JSON sites:JSON)],
);
} # end BEGIN
#===================================================================
=======
BEGIN {
__PACKAGE__->_define(
type => 'email',
methods => {
'listForwards:JSON' => [],
removeForward => [qw(forward)],
setForward => [qw(forward dest_email)],
========
sub get_converter # ($function)
{
my $convert = ($_[0] =~ s/:JSON$//
? 'WebService::NFSN::decode_json'
: '');
return $convert;
} # end get_converter
#-
=> 'account',
ro => [qw(balance balanceCash balanceCredit balanceHigh
status:JSON sites:JSON)],
rw => [qw(friendlyName)],
methods => {
addSite => [qw(site)],
fresh retry)],
methods => {
addRR => [qw(name type data ttl?)],
'listRRs:JSON' => [qw(name? type? data?)],
removeRR => [qw(name type data)],
updateSerial =