From f65c473c37783999d303971919b445b04332a244 Mon Sep 17 00:00:00 2001 From: sboyette Date: Tue, 15 Sep 2009 16:19:45 +0000 Subject: [PATCH 1/1] more test git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1787 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perl/lib/OpenSRF/Utils/JSON.pm | 42 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/perl/lib/OpenSRF/Utils/JSON.pm b/src/perl/lib/OpenSRF/Utils/JSON.pm index 6063f48..6e8e700 100644 --- a/src/perl/lib/OpenSRF/Utils/JSON.pm +++ b/src/perl/lib/OpenSRF/Utils/JSON.pm @@ -50,11 +50,13 @@ as. =cut sub register_class_hint { - # FIXME hint can't be a dupe - # FIXME fail unless we have hint and name + # FIXME hint can't be a dupe? + # FIXME fail unless we have hint and name? + # FIXME validate hint against IDL? my ($pkg, %args) = @_; - # FIXME why is the same thing shoved into two places? One mapping - # would suffice if class and hint were always returned together... + # FIXME maybe not just store a reference to %args; the lookup + # functions are really confusing at first glance as a side effect + # of this $_class_map{hints}{$args{hint}} = \%args; $_class_map{classes}{$args{name}} = \%args; } @@ -101,12 +103,25 @@ Intermediate routine called by L. sub rawJSON2perl { my ($pkg, $json) = @_; - # FIXME change regex conditional to '=~ /\S/' - return undef unless (defined $json and $json !~ /^\s*$/o); + return undef unless (defined $json and $json =~ /\S/o); return $parser->decode($json); } +=head2 rawPerl2JSON + +Intermediate routine used by L. + +=cut + +sub rawPerl2JSON { + # FIXME is there a reason this doesn't return undef with no + # content as rawJSON2perl does? + my ($pkg, $perl) = @_; + return $parser->encode($perl); +} + + =head2 JSONObject2Perl Final routine in the object re-vivification chain, called by L. @@ -152,19 +167,6 @@ sub JSONObject2Perl { } -=head2 rawPerl2JSON - -Intermediate routine used by L. - -=cut - -sub rawPerl2JSON { - # FIXME no validation of any sort - my ($pkg, $perl) = @_; - return $parser->encode($perl); -} - - =head2 perl2JSONObject =cut @@ -205,6 +207,7 @@ sub lookup_class { # they're named after. best case: flatten _class_map, since hints # and classes are identical my ($pkg, $hint) = @_; + return undef unless $hint; return $_class_map{hints}{$hint}{name} } @@ -215,6 +218,7 @@ sub lookup_class { sub lookup_hint { my ($pkg, $class) = @_; + return undef unless $class; return $_class_map{classes}{$class}{hint} } -- 2.43.2