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