| WSST documentation | Contained in the WSST distribution. |
WSST::SchemaParserManager - SchemaParserManager class of WSST
SchemaParserManager is a "Singleton" class. This class manages schema parsers.
Constructor.
Returns schema parser object for the specified filepath.
Returns "Singleton" instance.
Initialize this class.
http://code.google.com/p/wsst/
Mitsuhisa Oshikawa <mitsuhisa [at] gmail.com> Yusuke Kawasaki <u-suke [at] kawa.net>
Copyright 2008 WSS Project Team
| WSST documentation | Contained in the WSST distribution. |
package WSST::SchemaParserManager; use strict; use File::Basename qw(fileparse); use WSST::SchemaParser; use WSST::SchemaParser::YAML; our $VERSION = '0.1.1'; my $SINGLETON_INSTANCE = undef; sub new { my $class = shift; my $self = { parsers => [], parser_type_map => {}, }; return bless($self, $class); } sub get_schema_parser { my $self = shift; my $path = shift; my ($fname, $dir, $ext) = fileparse($path, qr/\.[^.]*/); return $self->{parser_type_map}->{$ext} if $self->{parser_type_map}->{$ext}; $ext =~ s/^\.//; $ext = uc($ext); my $cls = "WSST::SchemaParser::$ext"; eval "require $cls;"; if ($@) { die "parser not found: $path"; } return $cls->new(); } sub instance { my $class = shift; unless ($SINGLETON_INSTANCE) { $class->init(); } return $SINGLETON_INSTANCE; } sub init { my $class = shift; my $self = $SINGLETON_INSTANCE = $class->new(); foreach my $key (sort keys %WSST::SchemaParser::) { next if $key !~ /^(.+)::$/; my $cls = "WSST::SchemaParser::$1"; my $obj = $cls->new(); foreach my $type (@{$obj->types}) { $self->{parser_type_map}->{$type} = $obj; } } }
1;