File Coverage

blib/lib/Pod/Readme/Brief.pm
Criterion Covered Total %
statement 44 44 100.0
branch 11 22 50.0
condition 2 5 40.0
subroutine 7 7 100.0
pod 2 3 66.6
total 66 81 81.4


line stmt bran cond sub pod time code
1 1     1   407 use strict; use warnings;
  1     1   2  
  1         22  
  1         5  
  1         1  
  1         57  
2              
3             package Pod::Readme::Brief;
4              
5             our $VERSION = '1.003';
6              
7 1     1   1095 use Pod::Text;
  1         44326  
  1         635  
8              
9 1     1 1 909 sub new { my $class = shift; bless [ split /(?<=\n)/, ( join '', @_ ), -1 ], $class }
  1         550  
10              
11             sub find_pod_section {
12 3     3 0 6 my ( $self, $section, $do_loose ) = ( shift, @_ );
13 3 100       11 my $rx = $do_loose ? ".*?(?i:$section)" : "+(?i:$section)\$";
14 3         286 my @match = grep /^=head1\s$rx/ ... /^=head1\s/, @$self, "=head1 BUFFER STOP\n";
15 3         4 pop @match;
16 3 50       8 die "$section heading not found in POD\n" unless @match;
17 3         20 @match;
18             }
19              
20             sub render {
21 1     1 1 6 my ( $self, %arg ) = ( shift, @_ );
22              
23 1         3 my ( $name, @ambiguous ) = grep s/ - .*//s, $self->find_pod_section( NAME => 0 );
24 1 50 33     7 die "Could not parse NAME from the POD\n" unless defined $name and not @ambiguous;
25              
26 1         5 s/\A\s+//, s/\s+\z// for $name;
27 1 50       5 die "Bad module name $name\n" unless $name =~ /\A\w+(?:::\w+)*\z/;
28              
29 1         3 my @pod = "=pod\n\n";
30              
31 1 50       18 if ( my @encoding = grep /^=encoding\s/, @$self ) {
32 1 50       2 die "More than one =encoding directive found\n" if @encoding > 1;
33 1         2 push @pod, @encoding, "\n";
34             }
35              
36 1         3 my ( undef, @description ) = $self->find_pod_section( DESCRIPTION => 0 );
37 1         6 push @pod, "=head1 $name\n", @description;
38              
39 1         10 ( push @pod, $_ ), $pod[-1] =~ s!^\t!!mg for <<'__HERE__';
40             =head1 INSTALLATION
41              
42             This is a Perl module distribution. It should be installed with whichever
43             tool you use to manage your installation of Perl, e.g. any of
44              
45             cpanm .
46             cpan .
47             cpanp -i .
48              
49             Consult http://www.cpan.org/modules/INSTALL.html for further instruction.
50             __HERE__
51              
52 1         2 my $installer = $arg{'installer'};
53 1 50       4 ( push @pod, $_ ), $pod[-1] =~ s!^\t!!mg for $installer ? <<"__HERE__" : "\n";
54             Should you wish to install this module manually, the procedure is
55 1 0       10 ${ $installer eq 'eumm' ? \'
    50          
56             perl Makefile.PL
57             make
58 1         2 make test
59             make install
60 1         7 ' : $installer eq 'mb' ? \'
61 1         2 perl Build.PL
62             ./Build
63 1 50   1   544 ./Build test
  1         13  
  1         4  
  1         25  
64 1 50       573 ./Build install
65             ' : die "Unknown installer $installer\n" }
66             __HERE__
67              
68             push @pod, $self->find_pod_section( LICENSE => 1 );
69              
70 1   50     11 my $pod = join '', @pod;
71             my $text;
72 1         160  
73 1         10966 open my $in, '<', \$pod or die $!;
74             open my $out, '>', \$text or die $!;
75 1         25 my $parser = Pod::Text->new(
76             errors => 'die',
77             stderr => 1,
78             loose => 1,
79             indent => 0,
80             width => $arg{'width'} || 73,
81             );
82             $parser->parse_from_filehandle( $in, $out );
83             $text =~ s{\n+\z}{\n};
84              
85             $text;
86             }
87              
88             1;
89              
90             __END__