Upgrade to Test::Simple 0.64_03
[p5sagit/p5-mst-13.2.git] / lib / Pod / ParseUtils.pm
CommitLineData
e2c3adef 1#############################################################################
2# Pod/ParseUtils.pm -- helpers for POD parsing and conversion
3#
66aff6dd 4# Copyright (C) 1999-2000 by Marek Rouchal. All rights reserved.
e2c3adef 5# This file is part of "PodParser". PodParser is free software;
6# you can redistribute it and/or modify it under the same terms
7# as Perl itself.
8#############################################################################
9
10package Pod::ParseUtils;
11
12use vars qw($VERSION);
267d5541 13$VERSION = 1.35; ## Current version of this package
828c4421 14require 5.005; ## requires this Perl version or later
e2c3adef 15
16=head1 NAME
17
18Pod::ParseUtils - helpers for POD parsing and conversion
19
20=head1 SYNOPSIS
21
22 use Pod::ParseUtils;
23
24 my $list = new Pod::List;
25 my $link = Pod::Hyperlink->new('Pod::Parser');
26
27=head1 DESCRIPTION
28
29B<Pod::ParseUtils> contains a few object-oriented helper packages for
30POD parsing and processing (i.e. in POD formatters and translators).
31
32=cut
33
34#-----------------------------------------------------------------------------
35# Pod::List
36#
37# class to hold POD list info (=over, =item, =back)
38#-----------------------------------------------------------------------------
39
40package Pod::List;
41
42use Carp;
43
44=head2 Pod::List
45
46B<Pod::List> can be used to hold information about POD lists
47(written as =over ... =item ... =back) for further processing.
48The following methods are available:
49
50=over 4
51
92e3d63a 52=item Pod::List-E<gt>new()
e2c3adef 53
54Create a new list object. Properties may be specified through a hash
55reference like this:
56
57 my $list = Pod::List->new({ -start => $., -indent => 4 });
58
59See the individual methods/properties for details.
60
61=cut
62
63sub new {
64 my $this = shift;
65 my $class = ref($this) || $this;
66 my %params = @_;
67 my $self = {%params};
68 bless $self, $class;
69 $self->initialize();
70 return $self;
71}
72
73sub initialize {
74 my $self = shift;
75 $self->{-file} ||= 'unknown';
76 $self->{-start} ||= 'unknown';
77 $self->{-indent} ||= 4; # perlpod: "should be the default"
78 $self->{_items} = [];
79 $self->{-type} ||= '';
80}
81
92e3d63a 82=item $list-E<gt>file()
e2c3adef 83
84Without argument, retrieves the file name the list is in. This must
85have been set before by either specifying B<-file> in the B<new()>
86method or by calling the B<file()> method with a scalar argument.
87
88=cut
89
90# The POD file name the list appears in
91sub file {
92 return (@_ > 1) ? ($_[0]->{-file} = $_[1]) : $_[0]->{-file};
93}
94
92e3d63a 95=item $list-E<gt>start()
e2c3adef 96
97Without argument, retrieves the line number where the list started.
98This must have been set before by either specifying B<-start> in the
99B<new()> method or by calling the B<start()> method with a scalar
100argument.
101
102=cut
103
104# The line in the file the node appears
105sub start {
106 return (@_ > 1) ? ($_[0]->{-start} = $_[1]) : $_[0]->{-start};
107}
108
92e3d63a 109=item $list-E<gt>indent()
e2c3adef 110
111Without argument, retrieves the indent level of the list as specified
112in C<=over n>. This must have been set before by either specifying
113B<-indent> in the B<new()> method or by calling the B<indent()> method
114with a scalar argument.
115
116=cut
117
118# indent level
119sub indent {
120 return (@_ > 1) ? ($_[0]->{-indent} = $_[1]) : $_[0]->{-indent};
121}
122
92e3d63a 123=item $list-E<gt>type()
e2c3adef 124
125Without argument, retrieves the list type, which can be an arbitrary value,
126e.g. C<OL>, C<UL>, ... when thinking the HTML way.
127This must have been set before by either specifying
128B<-type> in the B<new()> method or by calling the B<type()> method
129with a scalar argument.
130
131=cut
132
133# The type of the list (UL, OL, ...)
134sub type {
135 return (@_ > 1) ? ($_[0]->{-type} = $_[1]) : $_[0]->{-type};
136}
137
92e3d63a 138=item $list-E<gt>rx()
e2c3adef 139
140Without argument, retrieves a regular expression for simplifying the
141individual item strings once the list type has been determined. Usage:
142E.g. when converting to HTML, one might strip the leading number in
143an ordered list as C<E<lt>OLE<gt>> already prints numbers itself.
144This must have been set before by either specifying
145B<-rx> in the B<new()> method or by calling the B<rx()> method
146with a scalar argument.
147
148=cut
149
150# The regular expression to simplify the items
151sub rx {
152 return (@_ > 1) ? ($_[0]->{-rx} = $_[1]) : $_[0]->{-rx};
153}
154
92e3d63a 155=item $list-E<gt>item()
e2c3adef 156
157Without argument, retrieves the array of the items in this list.
158The items may be represented by any scalar.
159If an argument has been given, it is pushed on the list of items.
160
161=cut
162
163# The individual =items of this list
164sub item {
165 my ($self,$item) = @_;
166 if(defined $item) {
167 push(@{$self->{_items}}, $item);
168 return $item;
169 }
170 else {
171 return @{$self->{_items}};
172 }
173}
174
92e3d63a 175=item $list-E<gt>parent()
e2c3adef 176
177Without argument, retrieves information about the parent holding this
178list, which is represented as an arbitrary scalar.
179This must have been set before by either specifying
180B<-parent> in the B<new()> method or by calling the B<parent()> method
181with a scalar argument.
182
183=cut
184
185# possibility for parsers/translators to store information about the
186# lists's parent object
187sub parent {
188 return (@_ > 1) ? ($_[0]->{-parent} = $_[1]) : $_[0]->{-parent};
189}
190
92e3d63a 191=item $list-E<gt>tag()
e2c3adef 192
193Without argument, retrieves information about the list tag, which can be
194any scalar.
195This must have been set before by either specifying
196B<-tag> in the B<new()> method or by calling the B<tag()> method
197with a scalar argument.
198
199=back
200
201=cut
202
203# possibility for parsers/translators to store information about the
204# list's object
205sub tag {
206 return (@_ > 1) ? ($_[0]->{-tag} = $_[1]) : $_[0]->{-tag};
207}
208
209#-----------------------------------------------------------------------------
210# Pod::Hyperlink
211#
212# class to manipulate POD hyperlinks (L<>)
213#-----------------------------------------------------------------------------
214
215package Pod::Hyperlink;
216
217=head2 Pod::Hyperlink
218
219B<Pod::Hyperlink> is a class for manipulation of POD hyperlinks. Usage:
220
221 my $link = Pod::Hyperlink->new('alternative text|page/"section in page"');
222
223The B<Pod::Hyperlink> class is mainly designed to parse the contents of the
224C<LE<lt>...E<gt>> sequence, providing a simple interface for accessing the
225different parts of a POD hyperlink for further processing. It can also be
226used to construct hyperlinks.
227
228=over 4
229
92e3d63a 230=item Pod::Hyperlink-E<gt>new()
e2c3adef 231
232The B<new()> method can either be passed a set of key/value pairs or a single
233scalar value, namely the contents of a C<LE<lt>...E<gt>> sequence. An object
234of the class C<Pod::Hyperlink> is returned. The value C<undef> indicates a
235failure, the error message is stored in C<$@>.
236
237=cut
238
239use Carp;
240
241sub new {
242 my $this = shift;
243 my $class = ref($this) || $this;
244 my $self = +{};
245 bless $self, $class;
246 $self->initialize();
247 if(defined $_[0]) {
248 if(ref($_[0])) {
249 # called with a list of parameters
250 %$self = %{$_[0]};
251 $self->_construct_text();
252 }
253 else {
254 # called with L<> contents
255 return undef unless($self->parse($_[0]));
256 }
257 }
258 return $self;
259}
260
261sub initialize {
262 my $self = shift;
263 $self->{-line} ||= 'undef';
264 $self->{-file} ||= 'undef';
265 $self->{-page} ||= '';
266 $self->{-node} ||= '';
267 $self->{-alttext} ||= '';
268 $self->{-type} ||= 'undef';
269 $self->{_warnings} = [];
270}
271
92e3d63a 272=item $link-E<gt>parse($string)
e2c3adef 273
274This method can be used to (re)parse a (new) hyperlink, i.e. the contents
275of a C<LE<lt>...E<gt>> sequence. The result is stored in the current object.
92e3d63a 276Warnings are stored in the B<warnings> property.
6facdfff 277E.g. sections like C<LE<lt>open(2)E<gt>> are deprecated, as they do not point
92e3d63a 278to Perl documents. C<LE<lt>DBI::foo(3p)E<gt>> is wrong as well, the manpage
279section can simply be dropped.
e2c3adef 280
281=cut
282
283sub parse {
284 my $self = shift;
285 local($_) = $_[0];
286 # syntax check the link and extract destination
9c6ed6d7 287 my ($alttext,$page,$node,$type,$quoted) = (undef,'','','',0);
e2c3adef 288
289 $self->{_warnings} = [];
290
291 # collapse newlines with whitespace
5c9f27e7 292 s/\s*\n+\s*/ /g;
293
e2c3adef 294 # strip leading/trailing whitespace
295 if(s/^[\s\n]+//) {
296 $self->warning("ignoring leading whitespace in link");
297 }
298 if(s/[\s\n]+$//) {
299 $self->warning("ignoring trailing whitespace in link");
300 }
301 unless(length($_)) {
302 _invalid_link("empty link");
303 return undef;
304 }
305
306 ## Check for different possibilities. This is tedious and error-prone
307 # we match all possibilities (alttext, page, section/item)
308 #warn "DEBUG: link=$_\n";
309
310 # only page
66aff6dd 311 # problem: a lot of people use (), or (1) or the like to indicate
312 # man page sections. But this collides with L<func()> that is supposed
313 # to point to an internal funtion...
9c6ed6d7 314 my $page_rx = '[\w.-]+(?:::[\w.-]+)*(?:[(](?:\d\w*|)[)]|)';
92e3d63a 315 # page name only
66aff6dd 316 if(m!^($page_rx)$!o) {
317 $page = $1;
e2c3adef 318 $type = 'page';
319 }
66aff6dd 320 # alttext, page and "section"
92e3d63a 321 elsif(m!^(.*?)\s*[|]\s*($page_rx)\s*/\s*"(.+)"$!o) {
66aff6dd 322 ($alttext, $page, $node) = ($1, $2, $3);
e2c3adef 323 $type = 'section';
9c6ed6d7 324 $quoted = 1; #... therefore | and / are allowed
e2c3adef 325 }
48f30392 326 # alttext and page
92e3d63a 327 elsif(m!^(.*?)\s*[|]\s*($page_rx)$!o) {
48f30392 328 ($alttext, $page) = ($1, $2);
329 $type = 'page';
330 }
331 # alttext and "section"
92e3d63a 332 elsif(m!^(.*?)\s*[|]\s*(?:/\s*|)"(.+)"$!) {
48f30392 333 ($alttext, $node) = ($1,$2);
334 $type = 'section';
9c6ed6d7 335 $quoted = 1;
48f30392 336 }
66aff6dd 337 # page and "section"
338 elsif(m!^($page_rx)\s*/\s*"(.+)"$!o) {
339 ($page, $node) = ($1, $2);
e2c3adef 340 $type = 'section';
9c6ed6d7 341 $quoted = 1;
e2c3adef 342 }
343 # page and item
66aff6dd 344 elsif(m!^($page_rx)\s*/\s*(.+)$!o) {
345 ($page, $node) = ($1, $2);
e2c3adef 346 $type = 'item';
347 }
66aff6dd 348 # only "section"
349 elsif(m!^/?"(.+)"$!) {
e2c3adef 350 $node = $1;
351 $type = 'section';
9c6ed6d7 352 $quoted = 1;
e2c3adef 353 }
354 # only item
66aff6dd 355 elsif(m!^\s*/(.+)$!) {
e2c3adef 356 $node = $1;
357 $type = 'item';
358 }
267d5541 359
360 # non-standard: Hyperlink with alt-text - doesn't remove protocol prefix, maybe it should?
361 elsif(m!^ \s* (.*?) \s* [|] \s* (\w+:[^:\s] [^\s|]*?) \s* $!ix) {
362 ($alttext,$node) = ($1,$2);
363 $type = 'hyperlink';
364 }
365
e2c3adef 366 # non-standard: Hyperlink
7b47f8ec 367 elsif(m!^(\w+:[^:\s]\S*)$!i) {
e2c3adef 368 $node = $1;
369 $type = 'hyperlink';
370 }
371 # alttext, page and item
92e3d63a 372 elsif(m!^(.*?)\s*[|]\s*($page_rx)\s*/\s*(.+)$!o) {
66aff6dd 373 ($alttext, $page, $node) = ($1, $2, $3);
e2c3adef 374 $type = 'item';
375 }
e2c3adef 376 # alttext and item
92e3d63a 377 elsif(m!^(.*?)\s*[|]\s*/(.+)$!) {
e2c3adef 378 ($alttext, $node) = ($1,$2);
379 }
e2c3adef 380 # must be an item or a "malformed" section (without "")
381 else {
382 $node = $_;
383 $type = 'item';
384 }
66aff6dd 385 # collapse whitespace in nodes
386 $node =~ s/\s+/ /gs;
e2c3adef 387
92e3d63a 388 # empty alternative text expands to node name
389 if(defined $alttext) {
390 if(!length($alttext)) {
391 $alttext = $node | $page;
392 }
393 }
394 else {
395 $alttext = '';
396 }
397
398 if($page =~ /[(]\w*[)]$/) {
399 $self->warning("(section) in '$page' deprecated");
400 }
7d8277e2 401 if(!$quoted && $node =~ m:[|/]: && $type ne 'hyperlink') {
66aff6dd 402 $self->warning("node '$node' contains non-escaped | or /");
403 }
404 if($alttext =~ m:[|/]:) {
405 $self->warning("alternative text '$node' contains non-escaped | or /");
e2c3adef 406 }
407 $self->{-page} = $page;
408 $self->{-node} = $node;
409 $self->{-alttext} = $alttext;
410 #warn "DEBUG: page=$page section=$section item=$item alttext=$alttext\n";
411 $self->{-type} = $type;
412 $self->_construct_text();
413 1;
414}
415
416sub _construct_text {
417 my $self = shift;
418 my $alttext = $self->alttext();
419 my $type = $self->type();
420 my $section = $self->node();
421 my $page = $self->page();
422 my $page_ext = '';
423 $page =~ s/([(]\w*[)])$// && ($page_ext = $1);
424 if($alttext) {
425 $self->{_text} = $alttext;
426 }
427 elsif($type eq 'hyperlink') {
428 $self->{_text} = $section;
429 }
430 else {
9c6ed6d7 431 $self->{_text} = ($section || '') .
432 (($page && $section) ? ' in ' : '') .
433 "$page$page_ext";
e2c3adef 434 }
435 # for being marked up later
436 # use the non-standard markers P<> and Q<>, so that the resulting
437 # text can be parsed by the translators. It's their job to put
438 # the correct hypertext around the linktext
439 if($alttext) {
440 $self->{_markup} = "Q<$alttext>";
441 }
442 elsif($type eq 'hyperlink') {
443 $self->{_markup} = "Q<$section>";
444 }
445 else {
9c6ed6d7 446 $self->{_markup} = (!$section ? '' : "Q<$section>") .
447 ($page ? ($section ? ' in ':'') . "P<$page>$page_ext" : '');
e2c3adef 448 }
449}
450
92e3d63a 451=item $link-E<gt>markup($string)
e2c3adef 452
453Set/retrieve the textual value of the link. This string contains special
454markers C<PE<lt>E<gt>> and C<QE<lt>E<gt>> that should be expanded by the
455translator's interior sequence expansion engine to the
456formatter-specific code to highlight/activate the hyperlink. The details
457have to be implemented in the translator.
458
459=cut
460
461#' retrieve/set markuped text
462sub markup {
463 return (@_ > 1) ? ($_[0]->{_markup} = $_[1]) : $_[0]->{_markup};
464}
465
92e3d63a 466=item $link-E<gt>text()
e2c3adef 467
468This method returns the textual representation of the hyperlink as above,
469but without markers (read only). Depending on the link type this is one of
470the following alternatives (the + and * denote the portions of the text
471that are marked up):
472
9c6ed6d7 473 +perl+ L<perl>
474 *$|* in +perlvar+ L<perlvar/$|>
475 *OPTIONS* in +perldoc+ L<perldoc/"OPTIONS">
476 *DESCRIPTION* L<"DESCRIPTION">
e2c3adef 477
478=cut
479
480# The complete link's text
481sub text {
482 $_[0]->{_text};
483}
484
92e3d63a 485=item $link-E<gt>warning()
e2c3adef 486
487After parsing, this method returns any warnings encountered during the
488parsing process.
489
490=cut
491
492# Set/retrieve warnings
493sub warning {
494 my $self = shift;
495 if(@_) {
496 push(@{$self->{_warnings}}, @_);
497 return @_;
498 }
499 return @{$self->{_warnings}};
500}
501
92e3d63a 502=item $link-E<gt>file()
503
504=item $link-E<gt>line()
e2c3adef 505
506Just simple slots for storing information about the line and the file
507the link was encountered in. Has to be filled in manually.
508
509=cut
510
511# The line in the file the link appears
512sub line {
513 return (@_ > 1) ? ($_[0]->{-line} = $_[1]) : $_[0]->{-line};
514}
515
516# The POD file name the link appears in
517sub file {
518 return (@_ > 1) ? ($_[0]->{-file} = $_[1]) : $_[0]->{-file};
519}
520
92e3d63a 521=item $link-E<gt>page()
e2c3adef 522
523This method sets or returns the POD page this link points to.
524
525=cut
526
527# The POD page the link appears on
528sub page {
529 if (@_ > 1) {
530 $_[0]->{-page} = $_[1];
531 $_[0]->_construct_text();
532 }
533 $_[0]->{-page};
534}
535
92e3d63a 536=item $link-E<gt>node()
e2c3adef 537
538As above, but the destination node text of the link.
539
540=cut
541
542# The link destination
543sub node {
544 if (@_ > 1) {
545 $_[0]->{-node} = $_[1];
546 $_[0]->_construct_text();
547 }
548 $_[0]->{-node};
549}
550
92e3d63a 551=item $link-E<gt>alttext()
e2c3adef 552
553Sets or returns an alternative text specified in the link.
554
555=cut
556
557# Potential alternative text
558sub alttext {
559 if (@_ > 1) {
560 $_[0]->{-alttext} = $_[1];
561 $_[0]->_construct_text();
562 }
563 $_[0]->{-alttext};
564}
565
92e3d63a 566=item $link-E<gt>type()
e2c3adef 567
568The node type, either C<section> or C<item>. As an unofficial type,
569there is also C<hyperlink>, derived from e.g. C<LE<lt>http://perl.comE<gt>>
570
571=cut
572
573# The type: item or headn
574sub type {
575 return (@_ > 1) ? ($_[0]->{-type} = $_[1]) : $_[0]->{-type};
576}
577
92e3d63a 578=item $link-E<gt>link()
e2c3adef 579
580Returns the link as contents of C<LE<lt>E<gt>>. Reciprocal to B<parse()>.
581
582=back
583
584=cut
585
586# The link itself
587sub link {
588 my $self = shift;
589 my $link = $self->page() || '';
590 if($self->node()) {
66aff6dd 591 my $node = $self->node();
592 $text =~ s/\|/E<verbar>/g;
593 $text =~ s:/:E<sol>:g;
e2c3adef 594 if($self->type() eq 'section') {
66aff6dd 595 $link .= ($link ? '/' : '') . '"' . $node . '"';
e2c3adef 596 }
597 elsif($self->type() eq 'hyperlink') {
598 $link = $self->node();
599 }
600 else { # item
66aff6dd 601 $link .= '/' . $node;
e2c3adef 602 }
603 }
604 if($self->alttext()) {
66aff6dd 605 my $text = $self->alttext();
606 $text =~ s/\|/E<verbar>/g;
607 $text =~ s:/:E<sol>:g;
608 $link = "$text|$link";
e2c3adef 609 }
610 $link;
611}
612
613sub _invalid_link {
614 my ($msg) = @_;
615 # this sets @_
616 #eval { die "$msg\n" };
617 #chomp $@;
618 $@ = $msg; # this seems to work, too!
619 undef;
620}
621
622#-----------------------------------------------------------------------------
623# Pod::Cache
624#
625# class to hold POD page details
626#-----------------------------------------------------------------------------
627
628package Pod::Cache;
629
630=head2 Pod::Cache
631
632B<Pod::Cache> holds information about a set of POD documents,
633especially the nodes for hyperlinks.
634The following methods are available:
635
636=over 4
637
92e3d63a 638=item Pod::Cache-E<gt>new()
e2c3adef 639
640Create a new cache object. This object can hold an arbitrary number of
641POD documents of class Pod::Cache::Item.
642
643=cut
644
645sub new {
646 my $this = shift;
647 my $class = ref($this) || $this;
648 my $self = [];
649 bless $self, $class;
650 return $self;
651}
652
92e3d63a 653=item $cache-E<gt>item()
e2c3adef 654
655Add a new item to the cache. Without arguments, this method returns a
656list of all cache elements.
657
658=cut
659
660sub item {
661 my ($self,%param) = @_;
662 if(%param) {
663 my $item = Pod::Cache::Item->new(%param);
664 push(@$self, $item);
665 return $item;
666 }
667 else {
668 return @{$self};
669 }
670}
671
92e3d63a 672=item $cache-E<gt>find_page($name)
e2c3adef 673
674Look for a POD document named C<$name> in the cache. Returns the
675reference to the corresponding Pod::Cache::Item object or undef if
676not found.
677
678=back
679
680=cut
681
682sub find_page {
683 my ($self,$page) = @_;
684 foreach(@$self) {
685 if($_->page() eq $page) {
686 return $_;
687 }
688 }
689 undef;
690}
691
692package Pod::Cache::Item;
693
694=head2 Pod::Cache::Item
695
696B<Pod::Cache::Item> holds information about individual POD documents,
697that can be grouped in a Pod::Cache object.
698It is intended to hold information about the hyperlink nodes of POD
699documents.
700The following methods are available:
701
702=over 4
703
92e3d63a 704=item Pod::Cache::Item-E<gt>new()
e2c3adef 705
706Create a new object.
707
708=cut
709
710sub new {
711 my $this = shift;
712 my $class = ref($this) || $this;
713 my %params = @_;
714 my $self = {%params};
715 bless $self, $class;
716 $self->initialize();
717 return $self;
718}
719
720sub initialize {
721 my $self = shift;
722 $self->{-nodes} = [] unless(defined $self->{-nodes});
723}
724
92e3d63a 725=item $cacheitem-E<gt>page()
e2c3adef 726
727Set/retrieve the POD document name (e.g. "Pod::Parser").
728
729=cut
730
731# The POD page
732sub page {
733 return (@_ > 1) ? ($_[0]->{-page} = $_[1]) : $_[0]->{-page};
734}
735
92e3d63a 736=item $cacheitem-E<gt>description()
e2c3adef 737
738Set/retrieve the POD short description as found in the C<=head1 NAME>
739section.
740
741=cut
742
743# The POD description, taken out of NAME if present
744sub description {
745 return (@_ > 1) ? ($_[0]->{-description} = $_[1]) : $_[0]->{-description};
746}
747
92e3d63a 748=item $cacheitem-E<gt>path()
e2c3adef 749
750Set/retrieve the POD file storage path.
751
752=cut
753
754# The file path
755sub path {
756 return (@_ > 1) ? ($_[0]->{-path} = $_[1]) : $_[0]->{-path};
757}
758
92e3d63a 759=item $cacheitem-E<gt>file()
e2c3adef 760
761Set/retrieve the POD file name.
762
763=cut
764
765# The POD file name
766sub file {
767 return (@_ > 1) ? ($_[0]->{-file} = $_[1]) : $_[0]->{-file};
768}
769
92e3d63a 770=item $cacheitem-E<gt>nodes()
e2c3adef 771
772Add a node (or a list of nodes) to the document's node list. Note that
773the order is kept, i.e. start with the first node and end with the last.
774If no argument is given, the current list of nodes is returned in the
775same order the nodes have been added.
776A node can be any scalar, but usually is a pair of node string and
777unique id for the C<find_node> method to work correctly.
778
779=cut
780
781# The POD nodes
782sub nodes {
783 my ($self,@nodes) = @_;
784 if(@nodes) {
785 push(@{$self->{-nodes}}, @nodes);
786 return @nodes;
787 }
788 else {
789 return @{$self->{-nodes}};
790 }
791}
792
92e3d63a 793=item $cacheitem-E<gt>find_node($name)
e2c3adef 794
48f30392 795Look for a node or index entry named C<$name> in the object.
796Returns the unique id of the node (i.e. the second element of the array
267d5541 797stored in the node array) or undef if not found.
e2c3adef 798
e2c3adef 799=cut
800
801sub find_node {
802 my ($self,$node) = @_;
48f30392 803 my @search;
804 push(@search, @{$self->{-nodes}}) if($self->{-nodes});
805 push(@search, @{$self->{-idx}}) if($self->{-idx});
806 foreach(@search) {
e2c3adef 807 if($_->[0] eq $node) {
808 return $_->[1]; # id
809 }
810 }
811 undef;
812}
813
92e3d63a 814=item $cacheitem-E<gt>idx()
48f30392 815
816Add an index entry (or a list of them) to the document's index list. Note that
817the order is kept, i.e. start with the first node and end with the last.
818If no argument is given, the current list of index entries is returned in the
819same order the entries have been added.
820An index entry can be any scalar, but usually is a pair of string and
821unique id.
822
92e3d63a 823=back
824
48f30392 825=cut
826
827# The POD index entries
828sub idx {
829 my ($self,@idx) = @_;
830 if(@idx) {
831 push(@{$self->{-idx}}, @idx);
832 return @idx;
833 }
834 else {
835 return @{$self->{-idx}};
836 }
837}
e2c3adef 838
839=head1 AUTHOR
840
aaa799f9 841Please report bugs using L<http://rt.cpan.org>.
842
843Marek Rouchal E<lt>marekr@cpan.orgE<gt>, borrowing
e2c3adef 844a lot of things from L<pod2man> and L<pod2roff> as well as other POD
845processing tools by Tom Christiansen, Brad Appleton and Russ Allbery.
846
847=head1 SEE ALSO
848
849L<pod2man>, L<pod2roff>, L<Pod::Parser>, L<Pod::Checker>,
850L<pod2html>
851
852=cut
853
8541;