File Coverage

blib/lib/Pod/PseudoPod/CrossReference.pm
Criterion Covered Total %
statement 60 63 95.2
branch 7 14 50.0
condition n/a
subroutine 22 22 100.0
pod 2 17 11.7
total 91 116 78.4


line stmt bran cond sub pod time code
1             package Pod::PseudoPod::CrossReference;
2 1     1   22612 use strict;
  1         3  
  1         60  
3 1     1   5 use base qw( Pod::PseudoPod );
  1         1  
  1         957  
4              
5 1     1   186165 use Carp;
  1         13  
  1         137  
6              
7 1     1   5 use vars qw( $VERSION );
  1         2  
  1         1681  
8             $VERSION = '0.02';
9              
10             sub new {
11 1     1 1 474 my $self = shift;
12 1         2 my $index = shift;
13 1         12 my $new = $self->SUPER::new(@_);
14 1         80 $new->accept_targets_as_text(
15             qw(author blockquote comment caution
16             editor epigraph example figure important note production
17             programlisting screen sidebar table tip warning)
18             );
19 1         61 $new->{'scratch'} = '';
20 1         4 $new->{'title'} = '';
21 1         2 map { $new->{_HNDL_TYPES}->{$_} = 1 }
  8         14  
22             qw( Z head0 head1 head2 head3 head4 figure table );
23 1         2 $new;
24             }
25              
26             sub _end {
27 5     5   8 my ($self, $type) = @_;
28 5         8 my $handler = $self->{'Handlers'}->{$type};
29 5 50       17 $self->{'title'} = $handler->($self, $self->{'scratch'}) if $handler;
30 5         16 $self->{'reftype'} = $type;
31 5         15 $self->{'scratch'} = '';
32 5         13 $self->{'capture'} = 0;
33             }
34              
35 7     7 0 1594 sub start_Z { $_[0]{'capture'} = 1; }
36              
37             sub end_Z {
38 7     7 0 54 my $self = shift;
39 7         13 my $handler = $self->{'Handlers'}->{'Z'};
40 7 50       30 $handler->($self, $self->{'scratch'}) if $handler;
41 7         27 $self->{'scratch'} = '';
42 7         16 $self->{'capture'} = 0;
43             }
44              
45 12 50   12 0 157 sub handle_text { $_[0]{'scratch'} .= $_[1] if $_[0]{'capture'}; }
46              
47 1     1 0 3398 sub start_head0 { $_[0]{'capture'} = 1; }
48 1     1 0 129 sub start_head1 { $_[0]{'capture'} = 1; }
49 1     1 0 122 sub start_head2 { $_[0]{'capture'} = 1; }
50 1     1 0 124 sub start_head3 { $_[0]{'capture'} = 1; }
51 1     1 0 272 sub start_head4 { $_[0]{'capture'} = 1; }
52              
53 1     1 0 17 sub end_head0 { _end($_[0], 'head0') }
54 1     1 0 10 sub end_head1 { _end($_[0], 'head1') }
55 1     1 0 54 sub end_head2 { _end($_[0], 'head2') }
56 1     1 0 10 sub end_head3 { _end($_[0], 'head3') }
57 1     1 0 9 sub end_head4 { _end($_[0], 'head4') }
58              
59             sub start_figure {
60 1     1 0 206 my $handler = $_[0]->{'Handlers'}->{'figure'};
61 1 50       6 $_[0]{'title'} = $handler->($_[0], $_[1]->{'title'}) if $handler;
62 1         5 $_[0]{'reftype'} = 'figure';
63             }
64              
65             sub start_table {
66 1     1 0 112 my $handler = $_[0]->{'Handlers'}->{'table'};
67 1 50       6 $_[0]{'title'} = $handler->($_[0], $_[1]->{'title'}) if $handler;
68 1         29 $_[0]{'reftype'} = 'table';
69             }
70              
71             #--- borrowed from XML::Parser
72             sub set_handlers {
73 2     2 1 206 my ($self, @handler_pairs) = @_;
74 2 50       6 croak("Uneven number of arguments to set_handlers method")
75             if (int(@handler_pairs) & 1);
76 2         3 my @ret;
77 2         6 while (@handler_pairs) {
78 8         9 my $type = shift @handler_pairs;
79 8         8 my $handler = shift @handler_pairs;
80 8 50       16 unless (defined($self->{_HNDL_TYPES}->{$type})) {
81 0         0 my @types = sort keys %{$self->{_HNDL_TYPES}};
  0         0  
82 0         0 croak("Unknown Parser handler type: $type\n Valid types: @types");
83             }
84 8         11 push(@ret, $type, $self->{'Handlers'}->{$type});
85 8         19 $self->{'Handlers'}->{$type} = $handler;
86             }
87 2         7 @ret;
88             }
89              
90             1;
91              
92             __END__