File Coverage

blib/lib/Pod/Index/Entry.pm
Criterion Covered Total %
statement 29 32 90.6
branch 3 6 50.0
condition n/a
subroutine 9 12 75.0
pod 6 7 85.7
total 47 57 82.4


line stmt bran cond sub pod time code
1             package Pod::Index::Entry;
2              
3 4     4   55 use 5.008;
  4         12  
  4         180  
4             $VERSION = '0.14';
5              
6 4     4   21 use strict;
  4         6  
  4         131  
7 4     4   20 use warnings;
  4         6  
  4         107  
8 4     4   2423 use Pod::Index::Extract;
  4         11  
  4         2033  
9              
10             sub new {
11 29     29 1 131 my ($class, %args) = @_;
12 29         175 my $self = bless {
13             %args,
14             }, $class;
15 29         173 return $self;
16             }
17              
18 0     0 1 0 sub podname { shift->{podname} }
19 6     6 1 5998 sub line { shift->{line} }
20 12     12 1 48 sub filename { shift->{filename} }
21 0     0 1 0 sub context { shift->{context} }
22 0     0 0 0 sub keyword { shift->{keyword} }
23              
24             sub pod {
25 6     6 1 13 my ($self) = @_;
26              
27 6 50       22 return $self->{pod} if defined $self->{pod};
28              
29 6         49 my $filename = $self->filename;
30              
31 6 50       279 open my $in, "<", $filename or die "couldn't open $filename $!\n";
32 6 50   1   84 open my $out, ">", \(my $pod) or die "couldn't open output fh: $!\n";
  1         9  
  1         3  
  1         7  
33              
34 6         1784 my $parser = Pod::Index::Extract->new(
35             ppi_entry => $self,
36             );
37              
38 6         207 <$in> for (1 .. $self->{line} - 1); # skip lines
39 6         249 $parser->parse_from_filehandle($in, $out);
40              
41 6         132 return $self->{pod} = $pod;
42             }
43              
44             1;
45              
46              
47             =head1 NAME
48              
49             Pod::Index::Entry - Represents Pod search result
50              
51             =head1 SYNOPSIS
52              
53             use Pod::Index::Entry;
54              
55             my $entry = Pod::Index::Entry->new(
56             keyword => 'constructors',
57             podname => 'perlobj',
58             line => 42,
59             filename => '/usr/lib/perl5/5.8.7/pod/perlobj.pod',
60             context => 'Using POD',
61             );
62              
63             # trivial accessors
64             my $podname = $entry->podname;
65             my $filename = $entry->filename;
66             my $line = $entry->line;
67             my $context = $entry->context;
68             my $keyword = $entry->keyword;
69              
70             # extract the POD for this entry
71             my $pod = $entry->pod;
72              
73             =head1 DESCRIPTION
74              
75             This class represents a POD index entry. An entry is defined by the
76             podname/filename, line number, and context. The entry object also has the
77             ability to extract the POD "scope" from the filename.
78              
79             =head1 METHODS
80              
81             =over
82              
83             =item new
84              
85             my $q = Pod::Index::Entry->new(%args);
86              
87             Create a new search object. Possible arguments are:
88              
89             =over
90              
91             =item podname
92              
93             The name of the pod, such as X.
94              
95             =item filename
96              
97             The filename for the pod, such as F.
98              
99             =item line
100              
101             The line number where the scope of this entry begins.
102              
103             =item context
104              
105             The title of the section that contains this entry.
106              
107             =back
108              
109             =item podname
110              
111             =item filename
112              
113             =item line
114              
115             =item context
116              
117             These are just simple accessors that return the value of these properties,
118             as given to the constructor.
119              
120             =item pod
121              
122             Extracts the POD for the scope of the entry from $self->filename, beginning at
123             $self->line. For a definition of I, see L. The POD
124             extraction is delegated to the L module.
125              
126             =back
127              
128             =head1 VERSION
129              
130             0.14
131              
132             =head1 SEE ALSO
133              
134             L,
135             L,
136             L
137              
138             =head1 AUTHOR
139              
140             Ivan Tubert-Brohman Eitub@cpan.orgE
141              
142             =head1 COPYRIGHT
143              
144             Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is
145             free software; you can redistribute it and/or modify it under the same terms as
146             Perl itself.
147              
148             =cut
149              
150              
151