1 package Module::Build::PodParser;
6 $VERSION = eval $VERSION;
15 # Try using Pod::Parser first
16 if (eval{ require Pod::Parser; 1; }) {
17 @ISA = qw(Pod::Parser);
18 $self = $package->SUPER::new(@_);
19 $self->{have_pod_parser} = 1;
22 *parse_from_filehandle = \&_myparse_from_filehandle;
23 $self = bless {have_pod_parser => 0, @_}, $package;
26 unless ($self->{fh}) {
27 die "No 'file' or 'fh' parameter given" unless $self->{file};
28 $self->{fh} = IO::File->new($self->{file}) or die "Couldn't open $self->{file}: $!";
34 sub _myparse_from_filehandle {
39 next unless /^=(?!cut)/ .. /^=cut/; # in POD
40 last if ($self->{abstract}) = /^ (?: [a-z:]+ \s+ - \s+ ) (.*\S) /ix;
45 next unless /^=head1\s+AUTHORS?/ ... /^=/;
47 push @author, $_ if /\@/;
49 return unless @author;
50 s/^\s+|\s+$//g foreach @author;
52 $self->{author} = \@author;
59 return $self->{abstract} if defined $self->{abstract};
61 $self->parse_from_filehandle($self->{fh});
63 return $self->{abstract};
68 return $self->{author} if defined $self->{author};
70 $self->parse_from_filehandle($self->{fh});
72 return $self->{author} || [];
75 ################## Pod::Parser overrides ###########
79 $self->SUPER::initialize();
83 my ($self, $cmd, $text) = @_;
84 if ( $cmd eq 'head1' ) {
87 $self->{_head} = $text;
92 my ($self, $text) = @_;
95 if ($self->{_head} eq 'NAME') {
96 my ($name, $abstract) = split( /\s+-\s+/, $text, 2 );
97 $self->{abstract} = $abstract;
98 } elsif ($self->{_head} =~ /^AUTHORS?$/) {
99 push @{$self->{author}}, $text if $text =~ /\@/;
104 sub interior_sequence {}