From a1237106ff15a200904b071ce7409c77904f4600 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Wed, 1 Dec 2010 21:30:40 +0100 Subject: [PATCH] JSArrayParser: Add JSJSONArrayParser as new (and preferred) method to parse JSON --- videosite/JSArrayParser.pm | 12 +++++++++++- videosite/JSJSONArrayParser.pm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 videosite/JSJSONArrayParser.pm 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; -- 1.8.3.1