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