File Coverage

blib/lib/Module/Build/PodParser.pm
Criterion Covered Total %
statement 41 43 95.3
branch 18 24 75.0
condition 2 2 100.0
subroutine 7 7 100.0
pod 0 4 0.0
total 68 80 85.0


line stmt bran cond sub pod time code
1             package Module::Build::PodParser;
2              
3 19     19   735 use strict;
  19         46  
  19         1003  
4 19     19   191 use warnings;
  19         69  
  19         15784  
5             our $VERSION = '0.42_33';
6             $VERSION = eval $VERSION;
7              
8             sub new {
9             # Perl is so fun.
10 73     73 0 4654 my $package = shift;
11              
12 73         128 my $self;
13 73         468 $self = bless {have_pod_parser => 0, @_}, $package;
14              
15 73 50       559 unless ($self->{fh}) {
16 0 0       0 die "No 'file' or 'fh' parameter given" unless $self->{file};
17 0 0       0 open($self->{fh}, '<', $self->{file}) or die "Couldn't open $self->{file}: $!";
18             }
19              
20 73         303 return $self;
21             }
22              
23             sub parse_from_filehandle {
24 73     73 0 186 my ($self, $fh) = @_;
25              
26 73         138 local $_;
27 73         1424 while (<$fh>) {
28 1608 100       4673 next unless /^ =encoding \s+ (\S+)/ix;
29 1     1   28 binmode $fh, ":encoding($1)";
  1         9  
  1         2  
  1         5  
30 1         970 last;
31             }
32 73         668 seek $fh, 0, 0;
33              
34 73         736 while (<$fh>) {
35 1008 100       2587 next unless /^=(?!cut)/ .. /^=cut/; # in POD
36             # Accept Name - abstract or C - abstract
37 691 100       2506 last if ($self->{abstract}) = /^ (?: [a-z_0-9:]+ | [BCIF] < [a-z_0-9:]+ > ) \s+ - \s+ (.*\S) /ix;
38             }
39              
40 73         201 my @author;
41 73         303 while (<$fh>) {
42 612 100       1991 next unless /^=head1\s+AUTHORS?/i ... /^=/;
43 345 100       1462 next if /^=/;
44 211 100       839 push @author, $_ if /\@/;
45             }
46 73 100       374 return unless @author;
47 67         923 s/^\s+|\s+$//g foreach @author;
48              
49 67         262 $self->{author} = \@author;
50              
51 67         297 return;
52             }
53              
54             sub get_abstract {
55 45     45 0 913 my $self = shift;
56 45 100       216 return $self->{abstract} if defined $self->{abstract};
57              
58 41         228 $self->parse_from_filehandle($self->{fh});
59              
60 41         745 return $self->{abstract};
61             }
62              
63             sub get_author {
64 32     32 0 2220 my $self = shift;
65 32 50       203 return $self->{author} if defined $self->{author};
66              
67 32         138 $self->parse_from_filehandle($self->{fh});
68              
69 32   100     1080 return $self->{author} || [];
70             }