📄 parseutils.pm
字号:
} else { $self->{_text} = ($section || '') . (($page && $section) ? ' in ' : '') . "$page$page_ext"; } # for being marked up later # use the non-standard markers P<> and Q<>, so that the resulting # text can be parsed by the translators. It's their job to put # the correct hypertext around the linktext if($alttext) { $self->{_markup} = "Q<$alttext>"; } elsif($type eq 'hyperlink') { $self->{_markup} = "Q<$section>"; } else { $self->{_markup} = (!$section ? '' : "Q<$section>") . ($page ? ($section ? ' in ':'') . "P<$page>$page_ext" : ''); }}=item $link-E<gt>markup($string)Set/retrieve the textual value of the link. This string contains specialmarkers C<PE<lt>E<gt>> and C<QE<lt>E<gt>> that should be expanded by thetranslator's interior sequence expansion engine to theformatter-specific code to highlight/activate the hyperlink. The detailshave to be implemented in the translator.=cut#' retrieve/set markuped textsub markup { return (@_ > 1) ? ($_[0]->{_markup} = $_[1]) : $_[0]->{_markup};}=item $link-E<gt>text()This method returns the textual representation of the hyperlink as above,but without markers (read only). Depending on the link type this is one ofthe following alternatives (the + and * denote the portions of the textthat are marked up): +perl+ L<perl> *$|* in +perlvar+ L<perlvar/$|> *OPTIONS* in +perldoc+ L<perldoc/"OPTIONS"> *DESCRIPTION* L<"DESCRIPTION">=cut# The complete link's textsub text { $_[0]->{_text};}=item $link-E<gt>warning()After parsing, this method returns any warnings encountered during theparsing process.=cut# Set/retrieve warningssub warning { my $self = shift; if(@_) { push(@{$self->{_warnings}}, @_); return @_; } return @{$self->{_warnings}};}=item $link-E<gt>file()=item $link-E<gt>line()Just simple slots for storing information about the line and the filethe link was encountered in. Has to be filled in manually.=cut# The line in the file the link appearssub line { return (@_ > 1) ? ($_[0]->{-line} = $_[1]) : $_[0]->{-line};}# The POD file name the link appears insub file { return (@_ > 1) ? ($_[0]->{-file} = $_[1]) : $_[0]->{-file};}=item $link-E<gt>page()This method sets or returns the POD page this link points to.=cut# The POD page the link appears onsub page { if (@_ > 1) { $_[0]->{-page} = $_[1]; $_[0]->_construct_text(); } $_[0]->{-page};}=item $link-E<gt>node()As above, but the destination node text of the link.=cut# The link destinationsub node { if (@_ > 1) { $_[0]->{-node} = $_[1]; $_[0]->_construct_text(); } $_[0]->{-node};}=item $link-E<gt>alttext()Sets or returns an alternative text specified in the link.=cut# Potential alternative textsub alttext { if (@_ > 1) { $_[0]->{-alttext} = $_[1]; $_[0]->_construct_text(); } $_[0]->{-alttext};}=item $link-E<gt>type()The node type, either C<section> or C<item>. As an unofficial type,there is also C<hyperlink>, derived from e.g. C<LE<lt>http://perl.comE<gt>>=cut# The type: item or headnsub type { return (@_ > 1) ? ($_[0]->{-type} = $_[1]) : $_[0]->{-type};}=item $link-E<gt>link()Returns the link as contents of C<LE<lt>E<gt>>. Reciprocal to B<parse()>.=back=cut# The link itselfsub link { my $self = shift; my $link = $self->page() || ''; if($self->node()) { my $node = $self->node(); $text =~ s/\|/E<verbar>/g; $text =~ s:/:E<sol>:g; if($self->type() eq 'section') { $link .= ($link ? '/' : '') . '"' . $node . '"'; } elsif($self->type() eq 'hyperlink') { $link = $self->node(); } else { # item $link .= '/' . $node; } } if($self->alttext()) { my $text = $self->alttext(); $text =~ s/\|/E<verbar>/g; $text =~ s:/:E<sol>:g; $link = "$text|$link"; } $link;}sub _invalid_link { my ($msg) = @_; # this sets @_ #eval { die "$msg\n" }; #chomp $@; $@ = $msg; # this seems to work, too! undef;}#-----------------------------------------------------------------------------# Pod::Cache## class to hold POD page details#-----------------------------------------------------------------------------package Pod::Cache;=head2 Pod::CacheB<Pod::Cache> holds information about a set of POD documents,especially the nodes for hyperlinks.The following methods are available:=over 4=item Pod::Cache-E<gt>new()Create a new cache object. This object can hold an arbitrary number ofPOD documents of class Pod::Cache::Item.=cutsub new { my $this = shift; my $class = ref($this) || $this; my $self = []; bless $self, $class; return $self;}=item $cache-E<gt>item()Add a new item to the cache. Without arguments, this method returns alist of all cache elements.=cutsub item { my ($self,%param) = @_; if(%param) { my $item = Pod::Cache::Item->new(%param); push(@$self, $item); return $item; } else { return @{$self}; }}=item $cache-E<gt>find_page($name)Look for a POD document named C<$name> in the cache. Returns thereference to the corresponding Pod::Cache::Item object or undef ifnot found.=back=cutsub find_page { my ($self,$page) = @_; foreach(@$self) { if($_->page() eq $page) { return $_; } } undef;}package Pod::Cache::Item;=head2 Pod::Cache::ItemB<Pod::Cache::Item> holds information about individual POD documents,that can be grouped in a Pod::Cache object.It is intended to hold information about the hyperlink nodes of PODdocuments.The following methods are available:=over 4=item Pod::Cache::Item-E<gt>new()Create a new object.=cutsub new { my $this = shift; my $class = ref($this) || $this; my %params = @_; my $self = {%params}; bless $self, $class; $self->initialize(); return $self;}sub initialize { my $self = shift; $self->{-nodes} = [] unless(defined $self->{-nodes});}=item $cacheitem-E<gt>page()Set/retrieve the POD document name (e.g. "Pod::Parser").=cut# The POD pagesub page { return (@_ > 1) ? ($_[0]->{-page} = $_[1]) : $_[0]->{-page};}=item $cacheitem-E<gt>description()Set/retrieve the POD short description as found in the C<=head1 NAME>section.=cut# The POD description, taken out of NAME if presentsub description { return (@_ > 1) ? ($_[0]->{-description} = $_[1]) : $_[0]->{-description};}=item $cacheitem-E<gt>path()Set/retrieve the POD file storage path.=cut# The file pathsub path { return (@_ > 1) ? ($_[0]->{-path} = $_[1]) : $_[0]->{-path};}=item $cacheitem-E<gt>file()Set/retrieve the POD file name.=cut# The POD file namesub file { return (@_ > 1) ? ($_[0]->{-file} = $_[1]) : $_[0]->{-file};}=item $cacheitem-E<gt>nodes()Add a node (or a list of nodes) to the document's node list. Note thatthe order is kept, i.e. start with the first node and end with the last.If no argument is given, the current list of nodes is returned in thesame order the nodes have been added.A node can be any scalar, but usually is a pair of node string andunique id for the C<find_node> method to work correctly.=cut# The POD nodessub nodes { my ($self,@nodes) = @_; if(@nodes) { push(@{$self->{-nodes}}, @nodes); return @nodes; } else { return @{$self->{-nodes}}; }}=item $cacheitem-E<gt>find_node($name)Look for a node or index entry named C<$name> in the object.Returns the unique id of the node (i.e. the second element of the arraystored in the node array) or undef if not found.=cutsub find_node { my ($self,$node) = @_; my @search; push(@search, @{$self->{-nodes}}) if($self->{-nodes}); push(@search, @{$self->{-idx}}) if($self->{-idx}); foreach(@search) { if($_->[0] eq $node) { return $_->[1]; # id } } undef;}=item $cacheitem-E<gt>idx()Add an index entry (or a list of them) to the document's index list. Note thatthe order is kept, i.e. start with the first node and end with the last.If no argument is given, the current list of index entries is returned in thesame order the entries have been added.An index entry can be any scalar, but usually is a pair of string andunique id.=back=cut# The POD index entriessub idx { my ($self,@idx) = @_; if(@idx) { push(@{$self->{-idx}}, @idx); return @idx; } else { return @{$self->{-idx}}; }}=head1 AUTHORPlease report bugs using L<http://rt.cpan.org>.Marek Rouchal E<lt>marekr@cpan.orgE<gt>, borrowinga lot of things from L<pod2man> and L<pod2roff> as well as other PODprocessing tools by Tom Christiansen, Brad Appleton and Russ Allbery.=head1 SEE ALSOL<pod2man>, L<pod2roff>, L<Pod::Parser>, L<Pod::Checker>,L<pod2html>=cut1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -