<xsl:template match="/">
package Fieldmapper;
-use JSON;
+use OpenSRF::Utils::JSON;
use Data::Dumper;
use base 'OpenSRF::Application';
use OpenILS::Application::AppUtils;
use OpenILS::Event;
use OpenSRF::EX qw/:try/;
-use JSON;
+use OpenSRF::Utils::JSON;
use Data::Dumper;
use OpenILS::Utils::Fieldmapper;
use Digest::MD5 qw/md5_hex/;
use OpenSRF::MultiSession;
use OpenSRF::AppSession;
use Time::HiRes qw/time/;
-use JSON;
my $config = shift;
sub {
my $ses = shift;
my $req = shift;
- print $req->{params}->[0] . "\t: " . JSON->perl2JSON($req->{response}->[0]->content)."\n";
+ print $req->{params}->[0] . "\t: " . OpenSRF::Utils::JSON->perl2JSON($req->{response}->[0]->content)."\n";
}
);
sub {
my $ses = shift;
my $req = shift;
- warn "record $req->{params}->[0] failed: ".JSON->perl2JSON($req->{response});
+ warn "record $req->{params}->[0] failed: " . OpenSRF::Utils::JSON->perl2JSON($req->{response});
}
);
-package JSON::number;
+package OpenSRF::Utils::JSON::number;
sub new {
my $class = shift;
my $x = shift || $class;
sub toString { defined($_[1]) ? ${$_[1]} : ${$_[0]} }
-package JSON::bool::true;
+package OpenSRF::Utils::JSON::bool::true;
sub new { return bless {} => __PACKAGE__ }
use overload ( '""' => \&toString );
use overload ( 'bool' => sub { 1 } );
sub toString { 'true' }
-package JSON::bool::false;
+package OpenSRF::Utils::JSON::bool::false;
sub new { return bless {} => __PACKAGE__ }
use overload ( '""' => \&toString );
use overload ( 'bool' => sub { 0 } );
sub toString { 'false' }
-package JSON;
+package OpenSRF::Utils::JSON;
use Unicode::Normalize;
use vars qw/%_class_map/;
$type = 'hash' if ($type eq '}');
$type = 'array' if ($type eq ']');
- JSON->register_class_hint(name => $hint, hint => $hint, type => $type);
+ OpenSRF::Utils::JSON->register_class_hint(name => $hint, hint => $hint, type => $type);
return $hint;
}
s/:/ => /sog;
# Do numbers...
- #s/\b(-?\d+\.?\d*)\b/ JSON::number::new($1) /sog;
+ #s/\b(-?\d+\.?\d*)\b/ OpenSRF::Utils::JSON::number::new($1) /sog;
# Change javascript stuff to perl...
s/null/ undef /sog;
- s/true/ bless( {}, "JSON::bool::true") /sog;
- s/false/ bless( {}, "JSON::bool::false") /sog;
+ s/true/ bless( {}, "OpenSRF::Utils::JSON::bool::true") /sog;
+ s/false/ bless( {}, "OpenSRF::Utils::JSON::bool::false") /sog;
my $ret;
return eval '$ret = '.$_;
} elsif ($element =~ /^\/\*/) {
next;
} elsif ($element =~ /^\d/) {
- $output .= "do { JSON::number::new($element) }";
+ $output .= "do { OpenSRF::Utils::JSON::number::new($element) }";
next;
} elsif ($element eq '{' or $element eq '[') {
$casting_depth++;
$output .= ' => ';
next;
} elsif ($element eq 'true') {
- $output .= 'bless( {}, "JSON::bool::true")';
+ $output .= 'bless( {}, "OpenSRF::Utils::JSON::bool::true")';
next;
} elsif ($element eq 'false') {
- $output .= 'bless( {}, "JSON::bool::false")';
+ $output .= 'bless( {}, "OpenSRF::Utils::JSON::bool::false")';
next;
}
if (!defined($perl)) {
$output = '' if $strict;
$output = 'null' unless $strict;
- } elsif (ref($perl) and ref($perl) =~ /^JSON/) {
+ } elsif (ref($perl) and ref($perl) =~ /^OpenSRF::Utils::JSON/) {
$output .= $perl;
} elsif ( ref($perl) && exists($_class_map{classes}{ref($perl)}) ) {
$output .= '/*--S '.$_class_map{classes}{ref($perl)}{hint}.'--*/';
} elsif (ref($perl) and ("$perl" =~ /^([^=]+)=(\w+)/o)) {
my $type = $2;
my $name = $1;
- JSON->register_class_hint(name => $name, hint => $name, type => lc($type));
+ OpenSRF::Utils::JSON->register_class_hint(name => $name, hint => $name, type => lc($type));
$output .= perl2JSON(undef,$perl, $strict);
} else {
$perl = NFC($perl);
if (!defined($perl)) {
$output = " "x$depth unless($nospace);
$output .= 'null';
- } elsif (ref($perl) and ref($perl) =~ /^JSON/) {
+ } elsif (ref($perl) and ref($perl) =~ /^OpenSRF::Utils::JSON/) {
$output = " "x$depth unless($nospace);
$output .= $perl;
} elsif ( ref($perl) && exists($_class_map{classes}{ref($perl)}) ) {
use OpenSRF::DomainObject::oilsMethod;
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use OpenSRF::Transport::PeerHandle;
+use OpenSRF::Utils::JSON;
use OpenSRF::Utils::Logger qw(:level);
use OpenSRF::Utils::SettingsClient;
use OpenSRF::Utils::Config;
}
}
- my $json = JSON->perl2JSON(\@doc);
+ my $json = OpenSRF::Utils::JSON->perl2JSON(\@doc);
$logger->internal("AppSession sending doc: $json");
$self->{peer_handle}->send(
use Time::HiRes qw/time/;
use OpenSRF::EX qw/:try/;
use Carp;
-use JSON;
+use OpenSRF::Utils::JSON;
#use OpenSRF::UnixServer; # to get the server class from UnixServer::App
sub DESTROY{};
for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
my $s = $sig->{params}->[$p];
my $a = $args[$p];
- if ($s->{class} && JSON->lookup_hint(ref $a) ne $s->{class}) {
+ if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
die "Incorrect param class at position $p : should be a '$$s{class}'";
} elsif ($s->{type}) {
if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
my $s = $sig->{params}->[$p];
my $a = $args[$p];
- if ($s->{class} && JSON->lookup_hint(ref $a) ne $s->{class}) {
+ if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
die "Incorrect param class at position $p : should be a '$$s{class}'";
} elsif ($s->{type}) {
if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
($args{object_hint} = $args{package}) =~ s/::/_/go;
}
- JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" );
+ OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" );
$_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app;
package OpenSRF::Application::Demo::MathDB;
-use JSON;
+use OpenSRF::Utils::JSON;
use base qw/OpenSRF::Application/;
use OpenSRF::Application;
use OpenSRF::DomainObject::oilsResponse qw/:status/;
my $n1 = shift;
my $n2 = shift;
my $a = $n1 + $n2;
- return JSON::number->new($a);
+ return OpenSRF::Utils::JSON::number->new($a);
}
__PACKAGE__->register_method( method => 'sub_1', api_name => 'dbmath.sub' );
my $n1 = shift;
my $n2 = shift;
my $a = $n1 - $n2;
- return JSON::number->new($a);
+ return OpenSRF::Utils::JSON::number->new($a);
}
__PACKAGE__->register_method( method => 'mult_1', api_name => 'dbmath.mult' );
my $n1 = shift;
my $n2 = shift;
my $a = $n1 * $n2;
- return JSON::number->new($a);
+ return OpenSRF::Utils::JSON::number->new($a);
}
__PACKAGE__->register_method( method => 'div_1', api_name => 'dbmath.div' );
my $n1 = shift;
my $n2 = shift;
my $a = $n1 / $n2;
- return JSON::number->new($a);
+ return OpenSRF::Utils::JSON::number->new($a);
}
1;
use OpenSRF::EX qw/:try/;
use OpenSRF::Utils qw/:common/;
use OpenSRF::Utils::Logger;
-use JSON;
+use OpenSRF::Utils::JSON;
use DBI;
use vars qw/$dbh $log $default_expire_time/;
$dbh->do('DELETE FROM storage WHERE name_id = ?;', {}, $name_id);
}
- $dbh->do('INSERT INTO storage (name_id,value) VALUES (?,?);', {}, $name_id, JSON->perl2JSON($value));
+ $dbh->do('INSERT INTO storage (name_id,value) VALUES (?,?);', {}, $name_id, OpenSRF::Utils::JSON->perl2JSON($value));
_flush_by_name($name);
_flush_by_name($name);
- return JSON->JSON2perl( $value->[1] );
+ return OpenSRF::Utils::JSON->JSON2perl( $value->[1] );
} catch Error with {
#my $e = shift;
#return $e;
my $values = $dbh->selectall_arrayref("SELECT value FROM storage WHERE name_id = ? ORDER BY id $order;", {}, $name_id);
- $client->respond( JSON->JSON2perl( $_->[0] ) ) for (@$values);
+ $client->respond( OpenSRF::Utils::JSON->JSON2perl( $_->[0] ) ) for (@$values);
_flush_by_name($name);
return undef;
my $value = $dbh->selectcol_arrayref('SELECT SUM(LENGTH(value)) FROM storage WHERE name_id = ?;', {}, $name_id);
- return JSON->JSON2perl( $value->[0] );
+ return OpenSRF::Utils::JSON->JSON2perl( $value->[0] );
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.queue.size',
my $value = $dbh->selectcol_arrayref('SELECT COUNT(*) FROM storage WHERE name_id = ?;', {}, $name_id);
- return JSON->JSON2perl( $value->[0] );
+ return OpenSRF::Utils::JSON->JSON2perl( $value->[0] );
}
__PACKAGE__->register_method(
api_name => 'opensrf.persist.queue.length',
_flush_by_name($name);
- return JSON->JSON2perl( $value->[1] );
+ return OpenSRF::Utils::JSON->JSON2perl( $value->[1] );
} catch Error with {
my $e = shift;
return undef;
_flush_by_name($name);
- return JSON->JSON2perl( $value->[1] );
+ return OpenSRF::Utils::JSON->JSON2perl( $value->[1] );
} catch Error with {
return undef;
};
package OpenSRF::DomainObject::oilsMessage;
-use JSON;
+use OpenSRF::Utils::JSON;
use OpenSRF::AppSession;
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use OpenSRF::Utils::Logger qw/:level/;
use warnings; use strict;
use OpenSRF::EX qw/:try/;
-JSON->register_class_hint(hint => 'osrfMessage', name => 'OpenSRF::DomainObject::oilsMessage', type => 'hash');
+OpenSRF::Utils::JSON->register_class_hint(hint => 'osrfMessage', name => 'OpenSRF::DomainObject::oilsMessage', type => 'hash');
sub toString {
my $self = shift;
my $pretty = shift;
- return JSON->perl2prettyJSON($self) if ($pretty);
- return JSON->perl2JSON($self);
+ return OpenSRF::Utils::JSON->perl2prettyJSON($self) if ($pretty);
+ return OpenSRF::Utils::JSON->perl2JSON($self);
}
sub new {
package OpenSRF::DomainObject::oilsMethod;
-use JSON;
-JSON->register_class_hint(hint => 'osrfMethod', name => 'OpenSRF::DomainObject::oilsMethod', type => 'hash');
+use OpenSRF::Utils::JSON;
+OpenSRF::Utils::JSON->register_class_hint(hint => 'osrfMethod', name => 'OpenSRF::DomainObject::oilsMethod', type => 'hash');
sub toString {
my $self = shift;
my $pretty = shift;
- return JSON->perl2prettyJSON($self) if ($pretty);
- return JSON->perl2JSON($self);
+ return OpenSRF::Utils::JSON->perl2prettyJSON($self) if ($pretty);
+ return OpenSRF::Utils::JSON->perl2JSON($self);
}
sub new {
package OpenSRF::DomainObject::oilsResponse;
use vars qw/@EXPORT_OK %EXPORT_TAGS/;
use Exporter;
-use JSON;
+use OpenSRF::Utils::JSON;
use base qw/Exporter/;
use OpenSRF::Utils::Logger qw/:level/;
-JSON->register_class_hint( hint => 'osrfResponse', name => 'OpenSRF::DomainObject::oilsResponse', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResponse', name => 'OpenSRF::DomainObject::oilsResponse', type => 'hash' );
BEGIN {
@EXPORT_OK = qw/STATUS_CONTINUE STATUS_OK STATUS_ACCEPTED
sub toString {
my $self = shift;
my $pretty = shift;
- return JSON->perl2prettyJSON($self) if ($pretty);
- return JSON->perl2JSON($self);
+ return OpenSRF::Utils::JSON->perl2prettyJSON($self) if ($pretty);
+ return OpenSRF::Utils::JSON->perl2JSON($self);
}
sub new {
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use base 'OpenSRF::DomainObject::oilsResponse';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfStatus', name => 'OpenSRF::DomainObject::oilsStatus', type => 'hash' );
=head1 NAME
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use base 'OpenSRF::DomainObject::oilsStatus';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectStatus', name => 'OpenSRF::DomainObject::oilsConnectStatus', type => 'hash' );
=head1 NAME
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use base 'OpenSRF::DomainObject::oilsStatus';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfContinueStatus', name => 'OpenSRF::DomainObject::oilsContinueStatus', type => 'hash' );
=head1 NAME
use OpenSRF::DomainObject::oilsPrimitive;
use base 'OpenSRF::DomainObject::oilsResponse';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfResult', name => 'OpenSRF::DomainObject::oilsResult', type => 'hash' );
$status = 'OK';
use base qw/OpenSRF::EX OpenSRF::DomainObject::oilsResponse/;
use vars qw/$status $statusCode/;
use Error;
-JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfException', name => 'OpenSRF::DomainObject::oilsException', type => 'hash' );
sub message {
my $self = shift;
use OpenSRF::EX;
use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfConnectException', name => 'OpenSRF::DomainObject::oilsConnectException', type => 'hash' );
=head1 NAME
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use base 'OpenSRF::DomainObject::oilsException';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfMethodException', name => 'OpenSRF::DomainObject::oilsMethodException', type => 'hash' );
=head1 NAME
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use base 'OpenSRF::DomainObject::oilsException';
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfServerError', name => 'OpenSRF::DomainObject::oilsServerError', type => 'hash' );
$status = 'Internal Server Error';
$statusCode = STATUS_INTERNALSERVERERROR;
use OpenSRF::EX;
use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfBrokenSession', name => 'OpenSRF::DomainObject::oilsBrokenSession', type => 'hash' );
$status = "Request on Disconnected Session";
$statusCode = STATUS_EXPFAILED;
use OpenSRF::EX;
use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
use vars qw/$status $statusCode/;
-JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfXMLParseError', name => 'OpenSRF::DomainObject::oilsXMLParseError', type => 'hash' );
$status = "XML Parse Error";
$statusCode = STATUS_EXPFAILED;
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use OpenSRF::EX;
use base qw/OpenSRF::DomainObject::oilsException OpenSRF::EX::ERROR/;
-JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
+OpenSRF::Utils::JSON->register_class_hint( hint => 'osrfAuthException', name => 'OpenSRF::DomainObject::oilsAuthException', type => 'hash' );
use vars qw/$status $statusCode/;
$status = "Authentication Failure";
$statusCode = STATUS_FORBIDDEN;
OpenSRF::Utils::Config->load( config_file => $bootstrap_config_file );
- JSON->register_class_hint( name => "OpenSRF::Application", hint => "method", type => "hash" );
+ OpenSRF::Utils::JSON->register_class_hint( name => "OpenSRF::Application", hint => "method", type => "hash" );
OpenSRF::Transport->message_envelope( "OpenSRF::Transport::SlimJabber::MessageWrapper" );
OpenSRF::Transport::PeerHandle->set_peer_client( "OpenSRF::Transport::SlimJabber::PeerConnection" );
use base 'OpenSRF';
use Time::HiRes qw/time/;
use OpenSRF::AppSession;
+use OpenSRF::Utils::JSON;
use OpenSRF::Utils::Logger qw(:level);
use OpenSRF::DomainObject::oilsResponse qw/:status/;
use OpenSRF::EX qw/:try/;
# Create a document from the JSON contained within the message
my $doc;
- eval { $doc = JSON->JSON2perl($body); };
+ eval { $doc = OpenSRF::Utils::JSON->JSON2perl($body); };
if( $@ ) {
$logger->transport( "Received bogus JSON: $@", INFO );
use OpenSRF::System;
use OpenSRF::Utils::SettingsClient;
use Time::HiRes qw(time);
-use JSON;
+use OpenSRF::Utils::JSON;
use vars qw/@ISA $app/;
use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
use Carp;
my $imp = $client->config_value("apps", $app, "implementation");
OpenSRF::Application::server_class($app);
OpenSRF::Application->application_implementation( $imp );
- JSON->register_class_hint( name => $imp, hint => $app, type => "hash" );
+ OpenSRF::Utils::JSON->register_class_hint( name => $imp, hint => $app, type => "hash" );
OpenSRF::Application->application_implementation->initialize()
if (OpenSRF::Application->application_implementation->can('initialize'));
use OpenSRF::Utils::Config;
use OpenSRF::Utils::SettingsClient;
use OpenSRF::EX qw(:try);
-use JSON;
+use OpenSRF::Utils::JSON;
my $log = 'OpenSRF::Utils::Logger';
my($self, $key, $value, $expiretime ) = @_;
return undef unless( defined $key and defined $value );
- $value = JSON->perl2JSON($value);
+ $value = OpenSRF::Utils::JSON->perl2JSON($value);
if($self->{persist}){ _load_methods(); }
my($self, $key ) = @_;
my $val = $self->{memcache}->get( $key );
- return JSON->JSON2perl($val) if defined($val);
+ return OpenSRF::Utils::JSON->JSON2perl($val) if defined($val);
if($self->{persist}){ _load_methods(); }
} else {
$self->{memcache}->set( $key, $val, $max_persist_time);
}
- return JSON->JSON2perl($val);
+ return OpenSRF::Utils::JSON->JSON2perl($val);
}
}
return undef;