JSArrayParser: Add JSJSONArrayParser as new (and preferred) method to parse JSON
[videosite.git] / videosite / JSArrayParser.pm
1 #
2 # This is a stub class for more complex JS*ArrayParser objects.
3 # It's new() method usually does _not_ return an object of
4 # type videosite::JSArrayParser, but rather a child object of itself
5 # which is able to do some actual work. The only time new() retuns
6 # an videosite::JSArrayParser onject is when no child objects are
7 # available.
8 #
9
10 package videosite::JSArrayParser;
11
12 use strict;
13
14 sub new {
15     my $class = shift;
16     my %params = @_;
17     my $self = {};
18
19     if ($class ne __PACKAGE__) {
20         # We were called from a child object. Return ourselves.
21         return bless($self, $class);
22     }
23
24     # Try to find a child object which is available and return that.
25
26     # See if videosite::JSJSONArrayParser is available
27     eval {
28         require videosite::JSJSONArrayParser;
29     };
30
31     unless($@) {
32         # Available. Return a JSJSONArrayParser object
33         return videosite::JSJSONArrayParser->new(%params);
34     }
35
36     # See if videosite::JSLexArrayParser is available
37     eval {
38         require videosite::JSLexArrayParser;
39     };
40
41     unless($@) {
42         # Available. Return a JSLexArrayParser object
43         return videosite::JSLexArrayParser->new(%params);
44     }
45
46     # See if JSSimleArrayParser is available
47     eval {
48         require videosite::JSSimpleArrayParser;
49     };
50
51     unless ($@) {
52         # Available. Return a JSSimpleArrayParser object
53         return videosite::JSSimpleArrayParser->new(%params);
54     }
55
56     # Nothing available. Return ourselves.
57     return bless($self, $class);
58 }
59
60 sub parse {
61     my $self = shift;
62
63     # No functionality here
64     return undef;
65 }
66
67 1;