Make cleanup of encodings, moving webpac closer to having
[webpac2] / lib / WebPAC / Parser.pm
index 13ed09a..bdd79ce 100644 (file)
@@ -49,6 +49,7 @@ Create new parser object.
   my $parser = new WebPAC::Parser(
        config => new WebPAC::Config(),
        base_path => '/optional/path/to/conf',
+       only_database => $only
   );
 
 =cut
@@ -240,9 +241,15 @@ sub _read_sources {
 
        my $lookup_src_cache;
 
+       my $only_database = $self->{only_database};
+       my $only_input = $self->{only_input};
+
        $self->{config}->iterate_inputs( sub {
                my ($input, $database) = @_;
 
+               return if ( $only_database && $database !~ m/$only_database/i );
+               return if ( $only_input && $input->{name} !~ m/$only_input/i );
+
                $log->debug("database: $database input = ", dump($input));
 
                foreach my $normalize (@{ $input->{normalize} }) {
@@ -325,6 +332,13 @@ sub _parse_source {
                        my ($Document,$Element) = @_;
 
                        $Element->isa('PPI::Token::Word') or return '';
+
+                       if ( $Element->content eq 'sub' ) {
+                               # repair demage done by prune of whitespace
+                               $Element->insert_after( PPI::Token::Whitespace->new(' ') );
+                               return '';
+                       }
+
                        $Element->content eq 'lookup' or return '';
 
                        $log->debug("expansion: ", $Element->snext_sibling);
@@ -399,7 +413,7 @@ sub _parse_source {
                        }
 
                        $e[7]->remove;
-                       $e[8]->insert_before( new PPI::Token::Quote::Single( "'$key'" ) );
+                       $e[8]->insert_before( PPI::Token::Quote::Single->new( "'$key'" ) );
                        $e[8]->remove;