- Add a fallback parser in case Parse::Lex is not available
[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 $self = {};
17
18     if ($class ne __PACKAGE__) {
19         # We were called from a child object. Return ourselves.
20         return bless($self, $class);
21     }
22
23     # Try to find a child object which is available and return that.
24     #
25     # See if videosite::JSLexArrayParser is available
26     eval {
27         require videosite::JSLexArrayParser;
28     };
29
30     unless($@) {
31         # Available. Return a JSLexArrayParser object
32         return videosite::JSLexArrayParser->new();
33     }
34
35     # See if JSSimleArrayParser is available
36     eval {
37         require videosite::JSSimpleArrayParser;
38     };
39
40     unless ($@) {
41         # Available. Return a JSSimpleArrayParser object
42         return videosite::JSSimpleArrayParser->new();
43     }
44
45     # Nothing available. Return ourselves.
46     return bless($self, $class);
47 }
48
49 sub parse {
50     my $self = shift;
51
52     # No functionality here
53     return undef;
54 }
55
56 1;