File Coverage

blib/lib/Pod/Readme/Brief.pm
Criterion Covered Total %
statement 39 39 100.0
branch 9 18 50.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 2 3 66.6
total 58 70 82.8


line stmt bran cond sub pod time code
1 1     1   433 use strict; use warnings;
  1     1   1  
  1         22  
  1         3  
  1         2  
  1         112  
2              
3             package Pod::Readme::Brief;
4              
5             our $VERSION = '1.001';
6              
7 1     1   460 use Pod::Text;
  1         42678  
  1         573  
8              
9 1     1 1 772 sub new { my $class = shift; bless [ split /(?<=\n)/, ( join '', @_ ), -1 ], $class }
  1         430  
10              
11             sub find_pod_section {
12 3     3 0 7 my ( $self, $section, $do_loose ) = ( shift, @_ );
13 3 100       22 my $rx = $do_loose ? ".*?(?i:$section)" : "+(?i:$section)\$";
14 3         269 my @match = grep /^=head1\s$rx/ ... /^=head1\s/, @$self, "=head1 BUFFER STOP\n";
15 3         6 pop @match;
16 3 50       7 die "$section heading not found in POD\n" unless @match;
17 3         19 @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         6 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         4 my @pod = $self->find_pod_section( DESCRIPTION => 0 );
30 1         6 $pod[0] =~ s/\s.*/ $name/;
31              
32 1         10 ( push @pod, $_ ), $pod[-1] =~ s!^\t!!mg for <<'__HERE__';
33             =head1 INSTALLATION
34              
35             This is a Perl module distribution. It should be installed with whichever
36             tool you use to manage your installation of Perl, e.g. any of
37              
38             cpanm .
39             cpan .
40             cpanp -i .
41              
42             Consult http://www.cpan.org/modules/INSTALL.html for further instruction.
43             __HERE__
44              
45 1         3 my $installer = $arg{'installer'};
46 1 50       3 ( push @pod, $_ ), $pod[-1] =~ s!^\t!!mg for $installer ? <<"__HERE__" : "\n";
47             Should you wish to install this module manually, the procedure is
48 1 0       12 ${ $installer eq 'eumm' ? \'
    50          
49             perl Makefile.PL
50             make
51 1         3 make test
52             make install
53 1         15 ' : $installer eq 'mb' ? \'
54             perl Build.PL
55 1 50   1   515 ./Build
  1         12  
  1         4  
  1         28  
56 1 50       601 ./Build test
57 1         8 ./Build install
58 1         175 ' : die "Unknown installer $installer\n" }
59 1         6706 __HERE__
60              
61 1         23 push @pod, $self->find_pod_section( LICENSE => 1 );
62              
63             my ( $pod, $text ) = join '', "=pod\n\n", @pod;
64              
65             open my $in, '<', \$pod or die $!;
66             open my $out, '>', \$text or die $!;
67             my $parser = Pod::Text->new( loose => 1, width => 73, indent => 0 );
68             $parser->parse_from_filehandle( $in, $out );
69             $text =~ s{\n+\z}{\n};
70              
71             $text;
72             }
73              
74             1;
75              
76             __END__