This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Module-Build to CPAN version 0.4204
[perl5.git] / cpan / Module-Build / lib / Module / Build / PodParser.pm
CommitLineData
bb4e9162
YST
1package Module::Build::PodParser;
2
3use strict;
7a827510 4use vars qw($VERSION);
71213e49 5$VERSION = '0.4204';
7a827510 6$VERSION = eval $VERSION;
bb4e9162
YST
7use vars qw(@ISA);
8
9sub new {
10 # Perl is so fun.
11 my $package = shift;
12
13 my $self;
2df9265e
DG
14 @ISA = ();
15 $self = bless {have_pod_parser => 0, @_}, $package;
bb4e9162
YST
16
17 unless ($self->{fh}) {
18 die "No 'file' or 'fh' parameter given" unless $self->{file};
46de787b 19 open($self->{fh}, '<', $self->{file}) or die "Couldn't open $self->{file}: $!";
bb4e9162
YST
20 }
21
22 return $self;
23}
24
2df9265e 25sub parse_from_filehandle {
bb4e9162 26 my ($self, $fh) = @_;
53fc1c7e 27
bb4e9162
YST
28 local $_;
29 while (<$fh>) {
30 next unless /^=(?!cut)/ .. /^=cut/; # in POD
1ce5ed3e 31 # Accept Name - abstract or C<Name> - abstract
46de787b 32 last if ($self->{abstract}) = /^ (?: [a-z_0-9:]+ | [BCIF] < [a-z_0-9:]+ > ) \s+ - \s+ (.*\S) /ix;
bb4e9162 33 }
53fc1c7e 34
bb4e9162
YST
35 my @author;
36 while (<$fh>) {
613f422f 37 next unless /^=head1\s+AUTHORS?/i ... /^=/;
bb4e9162
YST
38 next if /^=/;
39 push @author, $_ if /\@/;
40 }
41 return unless @author;
42 s/^\s+|\s+$//g foreach @author;
53fc1c7e 43
bb4e9162 44 $self->{author} = \@author;
53fc1c7e 45
bb4e9162
YST
46 return;
47}
48
49sub get_abstract {
50 my $self = shift;
51 return $self->{abstract} if defined $self->{abstract};
53fc1c7e 52
bb4e9162
YST
53 $self->parse_from_filehandle($self->{fh});
54
55 return $self->{abstract};
56}
57
58sub get_author {
59 my $self = shift;
60 return $self->{author} if defined $self->{author};
53fc1c7e 61
bb4e9162
YST
62 $self->parse_from_filehandle($self->{fh});
63
64 return $self->{author} || [];
65}