1 package Module::Build::PodParser;
12 # Try using Pod::Parser first
13 if (eval{ require Pod::Parser; 1; }) {
14 @ISA = qw(Pod::Parser);
15 $self = $package->SUPER::new(@_);
16 $self->{have_pod_parser} = 1;
19 *parse_from_filehandle = \&_myparse_from_filehandle;
20 $self = bless {have_pod_parser => 0, @_}, $package;
23 unless ($self->{fh}) {
24 die "No 'file' or 'fh' parameter given" unless $self->{file};
25 $self->{fh} = IO::File->new($self->{file}) or die "Couldn't open $self->{file}: $!";
31 sub _myparse_from_filehandle {
36 next unless /^=(?!cut)/ .. /^=cut/; # in POD
37 last if ($self->{abstract}) = /^ (?: [a-z:]+ \s+ - \s+ ) (.*\S) /ix;
42 next unless /^=head1\s+AUTHORS?/ ... /^=/;
44 push @author, $_ if /\@/;
46 return unless @author;
47 s/^\s+|\s+$//g foreach @author;
49 $self->{author} = \@author;
56 return $self->{abstract} if defined $self->{abstract};
58 $self->parse_from_filehandle($self->{fh});
60 return $self->{abstract};
65 return $self->{author} if defined $self->{author};
67 $self->parse_from_filehandle($self->{fh});
69 return $self->{author} || [];
72 ################## Pod::Parser overrides ###########
76 $self->SUPER::initialize();
80 my ($self, $cmd, $text) = @_;
81 if ( $cmd eq 'head1' ) {
84 $self->{_head} = $text;
89 my ($self, $text) = @_;
92 if ($self->{_head} eq 'NAME') {
93 my ($name, $abstract) = split( /\s+-\s+/, $text, 2 );
94 $self->{abstract} = $abstract;
95 } elsif ($self->{_head} =~ /^AUTHORS?$/) {
96 push @{$self->{author}}, $text if $text =~ /\@/;
101 sub interior_sequence {}