| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WSST::SchemaParserManager; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 23048 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use File::Basename qw(fileparse); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 137 |  | 
| 5 | 1 |  |  | 1 |  | 491 | use WSST::SchemaParser; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 6 | 1 |  |  | 1 |  | 504 | use WSST::SchemaParser::YAML; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 501 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.1.1'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | my $SINGLETON_INSTANCE = undef; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub new { | 
| 13 | 1 |  |  | 1 | 1 | 2 | my $class = shift; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 |  |  |  |  | 5 | my $self = { | 
| 16 |  |  |  |  |  |  | parsers => [], | 
| 17 |  |  |  |  |  |  | parser_type_map => {}, | 
| 18 |  |  |  |  |  |  | }; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 1 |  |  |  |  | 3 | return bless($self, $class); | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub get_schema_parser { | 
| 24 | 3 |  |  | 3 | 1 | 2948 | my $self = shift; | 
| 25 | 3 |  |  |  |  | 4 | my $path = shift; | 
| 26 | 3 |  |  |  |  | 139 | my ($fname, $dir, $ext) = fileparse($path, qr/\.[^.]*/); | 
| 27 | 3 | 100 |  |  |  | 42 | return $self->{parser_type_map}->{$ext} | 
| 28 |  |  |  |  |  |  | if $self->{parser_type_map}->{$ext}; | 
| 29 | 2 |  |  |  |  | 7 | $ext =~ s/^\.//; | 
| 30 | 2 |  |  |  |  | 5 | $ext = uc($ext); | 
| 31 | 2 |  |  |  |  | 5 | my $cls = "WSST::SchemaParser::$ext"; | 
| 32 | 2 |  |  |  |  | 129 | eval "require $cls;"; | 
| 33 | 2 | 100 |  |  |  | 382 | if ($@) { | 
| 34 | 1 |  |  |  |  | 9 | die "parser not found: $path"; | 
| 35 |  |  |  |  |  |  | } | 
| 36 | 1 |  |  |  |  | 13 | return $cls->new(); | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub instance { | 
| 40 | 1 |  |  | 1 | 1 | 798 | my $class = shift; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 1 | 50 |  |  |  | 5 | unless ($SINGLETON_INSTANCE) { | 
| 43 | 1 |  |  |  |  | 4 | $class->init(); | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  |  |  | 3 | return $SINGLETON_INSTANCE; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub init { | 
| 50 | 1 |  |  | 1 | 1 | 2 | my $class = shift; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 1 |  |  |  |  | 5 | my $self = $SINGLETON_INSTANCE = $class->new(); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  |  |  | 10 | foreach my $key (sort keys %WSST::SchemaParser::) { | 
| 55 | 6 | 100 |  |  |  | 16 | next if $key !~ /^(.+)::$/; | 
| 56 | 1 |  |  |  |  | 4 | my $cls = "WSST::SchemaParser::$1"; | 
| 57 | 1 |  |  |  |  | 9 | my $obj = $cls->new(); | 
| 58 | 1 |  |  |  |  | 3 | foreach my $type (@{$obj->types}) { | 
|  | 1 |  |  |  |  | 4 |  | 
| 59 | 2 |  |  |  |  | 10 | $self->{parser_type_map}->{$type} = $obj; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =head1 NAME | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | WSST::SchemaParserManager - SchemaParserManager class of WSST | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | SchemaParserManager is a "Singleton" class. | 
| 71 |  |  |  |  |  |  | This class manages schema parsers. | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 METHODS | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head2 new | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | Constructor. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head2 get_schema_parser | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | Returns schema parser object for the specified filepath. | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 instance | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | Returns "Singleton" instance. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head2 init | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | Initialize this class. | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | http://code.google.com/p/wsst/ | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 AUTHORS | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Mitsuhisa Oshikawa | 
| 98 |  |  |  |  |  |  | Yusuke Kawasaki | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | Copyright 2008 WSS Project Team | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =cut | 
| 105 |  |  |  |  |  |  | 1; |