From: Ralf Ertzinger Date: Wed, 1 Dec 2010 20:30:40 +0000 (+0100) Subject: JSArrayParser: Add JSJSONArrayParser as new (and preferred) method to parse JSON X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=a1237106ff15a200904b071ce7409c77904f4600;hp=d5b2cca8976d90b6bd9d098f983a132ebea164fb;p=videosite.git JSArrayParser: Add JSJSONArrayParser as new (and preferred) method to parse JSON --- diff --git a/videosite/JSArrayParser.pm b/videosite/JSArrayParser.pm index 8f9b729..37452fe 100644 --- a/videosite/JSArrayParser.pm +++ b/videosite/JSArrayParser.pm @@ -22,7 +22,17 @@ sub new { } # Try to find a child object which is available and return that. - # + + # See if videosite::JSJSONArrayParser is available + eval { + require videosite::JSJSONArrayParser; + }; + + unless($@) { + # Available. Return a JSJSONArrayParser object + return videosite::JSJSONArrayParser->new(%params); + } + # See if videosite::JSLexArrayParser is available eval { require videosite::JSLexArrayParser; diff --git a/videosite/JSJSONArrayParser.pm b/videosite/JSJSONArrayParser.pm new file mode 100644 index 0000000..052e325 --- /dev/null +++ b/videosite/JSJSONArrayParser.pm @@ -0,0 +1,30 @@ +# +# A helper class for parsing textual JS hashes into perl +# hashes +# +# This parser is based on the perl JSON module +# + +package videosite::JSJSONArrayParser; + +use videosite::JSArrayParser; +use JSON; +@ISA = qw(videosite::JSArrayParser); + +use strict; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + + return bless($self, $class); +} + +sub parse { + my $self = shift; + my $s = shift; + + return decode_json($s); +} + +1;