File Coverage

blib/lib/Pod/Index/Extract.pm
Criterion Covered Total %
statement 56 57 98.2
branch 27 32 84.3
condition 9 9 100.0
subroutine 10 10 100.0
pod 0 6 0.0
total 102 114 89.4


line stmt bran cond sub pod time code
1             package Pod::Index::Extract;
2              
3 4     4   61 use 5.008;
  4         13  
  4         239  
4             $VERSION = '0.14';
5              
6 4     4   21 use strict;
  4         8  
  4         131  
7 4     4   20 use warnings;
  4         7  
  4         121  
8              
9 4     4   23 use base qw(Pod::Parser);
  4         7  
  4         3436  
10              
11             sub begin_input {
12 6     6 0 9 my ($self) = @_;
13 6         505 $self->cutting(0); # force parser to notice that it's in POD mode
14             }
15              
16             sub verbatim {
17 4     4 0 7 my ($self, $text, $line_num, $pod_para) = @_;
18              
19             # verbatim should't have the X<> attached
20 4 50       11 return $self->ppi_done unless $self->{ppi_anchor_type};
21              
22 4         15 my $out_fh = $self->output_handle;
23 4         10 print $out_fh $text;
24 4         196 $self->{ppi_textblock_count}++;
25             }
26              
27             sub textblock {
28 9     9 0 22 my ($self, $text, $line_num, $pod_para) = @_;
29              
30             # should sanity check that the X<> is really here...
31             #print "<<<$text>>>\n";
32              
33 9         33 my $out_fh = $self->output_handle;
34              
35 9 100       24 unless ($self->{ppi_anchor_type}) {
36 2         3 $self->{ppi_anchor_type} = 'textblock';
37 2         7 $self->ppi_start;
38             }
39              
40             # only print the first paragraph if in textblock mode
41 9 100 100     41 return $self->ppi_done if $self->{ppi_anchor_type} eq 'textblock'
42             and $self->{ppi_textblock_count};
43              
44 8         20 print $out_fh $text;
45 8         424 $self->{ppi_textblock_count}++;
46             }
47              
48             sub command {
49 15     15 0 33 my ($self, $cmd, $text, $line_num, $pod_para) = @_;
50              
51             # should sanity check that the X<> is really here...
52              
53 15         46 my $out_fh = $self->output_handle;
54              
55 15 100       41 unless ($self->{ppi_anchor_type}) {
56 4         8 $self->{ppi_anchor_type} = 'command';
57 4         8 $self->{ppi_command} = $cmd;
58 4         10 $self->ppi_start;
59 4 100       11 if ($cmd eq 'item') {
60 2         5 print $out_fh "=over\n\n";
61             }
62             }
63              
64 15 100       37 return $self->ppi_done unless $self->{ppi_anchor_type} eq 'command';
65              
66 14         19 my $ppi_cmd = $self->{ppi_command};
67 14 50       46 return $self->ppi_done unless $ppi_cmd =~ /^(?:head|item)/; # XXX
68            
69             # check if we are out of scope
70 14 100       28 if ($self->{ppi_textblock_count}) {
71 8 100       33 if ($ppi_cmd =~ /^head(\d)/) {
    50          
72 2         4 my $initial_level = $1;
73 2 50       10 if ($cmd =~ /^head(\d)/) {
74 2         6 my $current_level = $1;
75 2 50       12 return $self->ppi_done if $current_level <= $initial_level;
76             }
77             } elsif ($ppi_cmd =~ /^item/) {
78 6 100 100     50 if ($cmd =~ /item|back/ and !$self->{ppi_depth}) {
    100          
    100          
79 2         7 return $self->ppi_done;
80             } elsif ($cmd eq 'over') {
81 1         3 $self->{ppi_depth}++;
82             } elsif ($cmd eq 'back') {
83 1         3 $self->{ppi_depth}--;
84             }
85             } else {
86 0         0 die "shouldn't be here ";
87             }
88             }
89              
90 10         535 print $out_fh $pod_para->raw_text;
91             }
92              
93             sub ppi_start {
94 6     6 0 11 my ($self) = @_;
95             }
96              
97             sub ppi_done {
98 6     6 0 9 my ($self) = @_;
99 6         19 my $out_fh = $self->output_handle;
100 6 100 100     37 if ($self->{ppi_command} and $self->{ppi_command} eq 'item') {
101 2         5 print $out_fh "=back\n\n";
102             }
103              
104              
105 6         27 my $fh = $self->input_handle;
106 6         246 seek $fh, 0, 2; # EOF
107             }
108              
109             1;
110              
111             __END__