fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / JSArrayParser.pm
index 20e6e0e..bbc60de 100644 (file)
@@ -1,55 +1,37 @@
 #
-# A helper class for parsing textual JS hashes into perl 
-# hashes
-#
-# The parser is in jsarray.yp, to regenerate you'll need the Parse::YAPP
-# package. Use 'yapp -m videosite::jsarray -s jsarray.yp' to regenerate
+# This is a stub class for more complex JS*ArrayParser objects.
+# It's new() method usually does _not_ return an object of
+# type videosite::JSArrayParser, but rather a child object of itself
+# which is able to do some actual work. The only time new() retuns
+# an videosite::JSArrayParser onject is when no child objects are
+# available.
 #
 
 package videosite::JSArrayParser;
 
-use Parse::Lex;
-use videosite::jsarray;
 use strict;
 
-my @tokens = (
-    COLON  => '[:]',
-    RIGHTC => '[\}]',
-    LEFTC => '[\{]',
-    QUOTE => '[\"]',
-    COMMA => '[,]',
-    ID =>    '[\w_%\.\+-]+'
-);
-
 sub new {
     my $class = shift;
-    my $self = {
-        '_PARSER' => videosite::jsarray->new(),
-        '_LEXER' => Parse::Lex->new(@tokens),
-    };
+    my %params = @_;
+    my $self = {};
+
+    if ($class ne __PACKAGE__) {
+        # We were called from a child object. Return ourselves.
+        return bless($self, $class);
+    }
 
-    return bless($self, $class);
+    # Try to find a child object which is available and return that.
+
+    require videosite::JSJSONArrayParser;
+    return videosite::JSJSONArrayParser->new(%params);
 }
 
 sub parse {
     my $self = shift;
-    my $s = shift;
-    my @result;
-    my $l = $self->{'_LEXER'};
-
-    $l->from($s);
-    @result = $self->{'_PARSER'}->YYParse(
-        yylex => sub {
-            my $tok = $l->next();
-            return ('', undef) unless $tok;
-            return ('', undef) if $l->eoi();
-            return ($tok->name(), $tok->text());
-        },
-        yyerror => sub {
-            $_[0]->YYAbort();
-        },
-        yydebug => 0x0);
-    return $result[0]?{@{$result[0]}}:undef;
+
+    # No functionality here
+    return undef;
 }
 
 1;