File: PodOPTIONSParser.pm

package info (click to toggle)
libvcp-perl 0.9-20050110-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,608 kB
  • ctags: 827
  • sloc: perl: 18,194; makefile: 42; sh: 11
file content (103 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package VCP::PodOPTIONSParser;

=head1 NAME

VCP::PodOPTIONSParser - Parse OPTIONS sections from a set of source files.

=head1 SYNOPSIS

   use VCP::PodOPTIONSParser;
   my $p = VCP::PodOPTIONSParser->new;
   my $options_hash = $p->parse( @packages_or_filenames );

=head1 DESCRIPTION

Returns a hash of all C<=item>s found in all OPTIONS sections in the
given filenames.  Warns if duplicate options are found.

ASSUMES ALL PACKAGES REFERRED TO ARE ALREADY LOADED.  %INC is used to
locate their source code.

Converts packages (any string matching /\w[:\w]+/) to filenames.

=cut

$VERSION = 0.1 ;

use Pod::Text;
@ISA = qw( Pod::Text );

use strict;

use VCP::Logger qw( BUG );

sub verbatim {
   my $self = shift;
   my ( $paragraph ) = @_;

   1 while chomp $paragraph;
   push @{$self->{Options}->{$self->{CurOption}}}, $paragraph
      if defined $self->{CurOption};
}

sub textblock {
   my $self = shift;
   my ( $paragraph, $line ) = @_;

   1 while chomp $paragraph;
   push @{$self->{Options}->{$self->{CurOption}}},
      $self->interpolate( $paragraph, $line )
      if defined $self->{CurOption};
}

sub command {
   my $self = shift;
   my ( $command, $paragraph, $line ) = @_;

   if ( $command eq "item" ) {
       1 while chomp $paragraph;
       $self->{CurOption} = $self->interpolate( $paragraph, $line );
   }
   else {
       $self->{CurOption} = undef;
   }

}

sub parse {
   my $self = shift;
   $self = $self->new unless ref $self;

   $self->select( "OPTIONS" );

   $self->{Options} = {};

   for my $fn ( @_ ) {
      if ( $fn =~ /\A\w[:\w]+\z/ ) {
         ( my $key = $fn ) =~ s/::/\//g;
         $key .= ".pm";
         BUG "can't find source for $fn in \%INC"
            unless defined $INC{$key};
         $fn = $INC{$key};
      }
      $self->parse_from_file( $fn );
   }

   return $self->{Options};
}

=head1 COPYRIGHT

Copyright 2000, Perforce Software, Inc.  All Rights Reserved.

This module and the VCP package are licensed according to the terms given in
the file LICENSE accompanying this distribution, a copy of which is included in
L<vcp>.

=head1 AUTHOR

Barrie Slaymaker <barries@slaysys.com>

=cut

1