X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FJSArrayParser.pm;h=bbc60de857acc5a2bd39e0184c4bc1f4164e4ad3;hb=b929656189ab5eeb2e8378bb7f3299ef9597a5a1;hp=20e6e0ef7813cfb9cf679893b6e94cb065ba6bfb;hpb=7b6cd96a0ad9a3bed4f771df3cc3d541470427f8;p=videosite.git diff --git a/videosite/JSArrayParser.pm b/videosite/JSArrayParser.pm index 20e6e0e..bbc60de 100644 --- a/videosite/JSArrayParser.pm +++ b/videosite/JSArrayParser.pm @@ -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;