⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inputobjects.pm

📁 mrtg 监控,请认真阅读您的文件包然后写出其具体功能
💻 PM
📖 第 1 页 / 共 2 页
字号:
############################################################################## Pod/InputObjects.pm -- package which defines objects for input streams# and paragraphs and commands when parsing POD docs.## Copyright (C) 1996-2000 by Bradford Appleton. All rights reserved.# This file is part of "PodParser". PodParser is free software;# you can redistribute it and/or modify it under the same terms# as Perl itself.#############################################################################package Pod::InputObjects;use vars qw($VERSION);$VERSION = 1.13;  ## Current version of this packagerequire  5.005;    ## requires this Perl version or later#############################################################################=head1 NAMEPod::InputObjects - objects representing POD input paragraphs, commands, etc.=head1 SYNOPSIS    use Pod::InputObjects;=head1 REQUIRESperl5.004, Carp=head1 EXPORTSNothing.=head1 DESCRIPTIONThis module defines some basic input objects used by B<Pod::Parser> whenreading and parsing POD text from an input source. The following objectsare defined:=over 4=begin __PRIVATE__=item package B<Pod::InputSource>An object corresponding to a source of POD input text. It is mostly awrapper around a filehandle or C<IO::Handle>-type object (or anythingthat implements the C<getline()> method) which keeps track of someadditional information relevant to the parsing of PODs.=end __PRIVATE__=item package B<Pod::Paragraph>An object corresponding to a paragraph of POD input text. It may be aplain paragraph, a verbatim paragraph, or a command paragraph (seeL<perlpod>).=item package B<Pod::InteriorSequence>An object corresponding to an interior sequence command from the PODinput text (see L<perlpod>).=item package B<Pod::ParseTree>An object corresponding to a tree of parsed POD text. Each "node" ina parse-tree (or I<ptree>) is either a text-string or a reference toa B<Pod::InteriorSequence> object. The nodes appear in the parse-treein the order in which they were parsed from left-to-right.=backEach of these input objects are described in further detail in thesections which follow.=cut#############################################################################use strict;#use diagnostics;#use Carp;#############################################################################package Pod::InputSource;##---------------------------------------------------------------------------=begin __PRIVATE__=head1 B<Pod::InputSource>This object corresponds to an input source or stream of PODdocumentation. When parsing PODs, it is necessary to associate and storecertain context information with each input source. All of thisinformation is kept together with the stream itself in one of theseC<Pod::InputSource> objects. Each such object is merely a wrapper aroundan C<IO::Handle> object of some kind (or at least something thatimplements the C<getline()> method). They have the followingmethods/attributes:=end __PRIVATE__=cut##---------------------------------------------------------------------------=begin __PRIVATE__=head2 B<new()>        my $pod_input1 = Pod::InputSource->new(-handle => $filehandle);        my $pod_input2 = new Pod::InputSource(-handle => $filehandle,                                              -name   => $name);        my $pod_input3 = new Pod::InputSource(-handle => \*STDIN);        my $pod_input4 = Pod::InputSource->new(-handle => \*STDIN,                                               -name => "(STDIN)");This is a class method that constructs a C<Pod::InputSource> object andreturns a reference to the new input source object. It takes one or morekeyword arguments in the form of a hash. The keyword C<-handle> isrequired and designates the corresponding input handle. The keywordC<-name> is optional and specifies the name associated with the inputhandle (typically a file name).=end __PRIVATE__=cutsub new {    ## Determine if we were called via an object-ref or a classname    my $this = shift;    my $class = ref($this) || $this;    ## Any remaining arguments are treated as initial values for the    ## hash that is used to represent this object. Note that we default    ## certain values by specifying them *before* the arguments passed.    ## If they are in the argument list, they will override the defaults.    my $self = { -name        => '(unknown)',                 -handle      => undef,                 -was_cutting => 0,                 @_ };    ## Bless ourselves into the desired class and perform any initialization    bless $self, $class;    return $self;}##---------------------------------------------------------------------------=begin __PRIVATE__=head2 B<name()>        my $filename = $pod_input->name();        $pod_input->name($new_filename_to_use);This method gets/sets the name of the input source (usually a filename).If no argument is given, it returns a string containing the name ofthe input source; otherwise it sets the name of the input source to thecontents of the given argument.=end __PRIVATE__=cutsub name {   (@_ > 1)  and  $_[0]->{'-name'} = $_[1];   return $_[0]->{'-name'};}## allow 'filename' as an alias for 'name'*filename = \&name;##---------------------------------------------------------------------------=begin __PRIVATE__=head2 B<handle()>        my $handle = $pod_input->handle();Returns a reference to the handle object from which input is read (theone used to contructed this input source object).=end __PRIVATE__=cutsub handle {   return $_[0]->{'-handle'};}##---------------------------------------------------------------------------=begin __PRIVATE__=head2 B<was_cutting()>        print "Yes.\n" if ($pod_input->was_cutting());The value of the C<cutting> state (that the B<cutting()> method wouldhave returned) immediately before any input was read from this inputstream. After all input from this stream has been read, the C<cutting>state is restored to this value.=end __PRIVATE__=cutsub was_cutting {   (@_ > 1)  and  $_[0]->{-was_cutting} = $_[1];   return $_[0]->{-was_cutting};}##---------------------------------------------------------------------------#############################################################################package Pod::Paragraph;##---------------------------------------------------------------------------=head1 B<Pod::Paragraph>An object representing a paragraph of POD input text.It has the following methods/attributes:=cut##---------------------------------------------------------------------------=head2 Pod::Paragraph-E<gt>B<new()>        my $pod_para1 = Pod::Paragraph->new(-text => $text);        my $pod_para2 = Pod::Paragraph->new(-name => $cmd,                                            -text => $text);        my $pod_para3 = new Pod::Paragraph(-text => $text);        my $pod_para4 = new Pod::Paragraph(-name => $cmd,                                           -text => $text);        my $pod_para5 = Pod::Paragraph->new(-name => $cmd,                                            -text => $text,                                            -file => $filename,                                            -line => $line_number);This is a class method that constructs a C<Pod::Paragraph> object andreturns a reference to the new paragraph object. It may be given one ortwo keyword arguments. The C<-text> keyword indicates the correspondingtext of the POD paragraph. The C<-name> keyword indicates the name ofthe corresponding POD command, such as C<head1> or C<item> (it shouldI<not> contain the C<=> prefix); this is needed only if the PODparagraph corresponds to a command paragraph. The C<-file> and C<-line>keywords indicate the filename and line number corresponding to thebeginning of the paragraph =cutsub new {    ## Determine if we were called via an object-ref or a classname    my $this = shift;    my $class = ref($this) || $this;    ## Any remaining arguments are treated as initial values for the    ## hash that is used to represent this object. Note that we default    ## certain values by specifying them *before* the arguments passed.    ## If they are in the argument list, they will override the defaults.    my $self = {          -name       => undef,          -text       => (@_ == 1) ? $_[0] : undef,          -file       => '<unknown-file>',          -line       => 0,          -prefix     => '=',          -separator  => ' ',          -ptree => [],          @_    };    ## Bless ourselves into the desired class and perform any initialization    bless $self, $class;    return $self;}##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<cmd_name()>        my $para_cmd = $pod_para->cmd_name();If this paragraph is a command paragraph, then this method will return the name of the command (I<without> any leading C<=> prefix).=cutsub cmd_name {   (@_ > 1)  and  $_[0]->{'-name'} = $_[1];   return $_[0]->{'-name'};}## let name() be an alias for cmd_name()*name = \&cmd_name;##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<text()>        my $para_text = $pod_para->text();This method will return the corresponding text of the paragraph.=cutsub text {   (@_ > 1)  and  $_[0]->{'-text'} = $_[1];   return $_[0]->{'-text'};}       ##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<raw_text()>        my $raw_pod_para = $pod_para->raw_text();This method will return the I<raw> text of the POD paragraph, exactlyas it appeared in the input.=cutsub raw_text {   return $_[0]->{'-text'}  unless (defined $_[0]->{'-name'});   return $_[0]->{'-prefix'} . $_[0]->{'-name'} .           $_[0]->{'-separator'} . $_[0]->{'-text'};}##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<cmd_prefix()>        my $prefix = $pod_para->cmd_prefix();If this paragraph is a command paragraph, then this method will return the prefix used to denote the command (which should be the string "="or "==").=cutsub cmd_prefix {   return $_[0]->{'-prefix'};}##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<cmd_separator()>        my $separator = $pod_para->cmd_separator();If this paragraph is a command paragraph, then this method will returnthe text used to separate the command name from the rest of theparagraph (if any).=cutsub cmd_separator {   return $_[0]->{'-separator'};}##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<parse_tree()>        my $ptree = $pod_parser->parse_text( $pod_para->text() );        $pod_para->parse_tree( $ptree );        $ptree = $pod_para->parse_tree();This method will get/set the corresponding parse-tree of the paragraph's text.=cutsub parse_tree {   (@_ > 1)  and  $_[0]->{'-ptree'} = $_[1];   return $_[0]->{'-ptree'};}       ## let ptree() be an alias for parse_tree()*ptree = \&parse_tree;##---------------------------------------------------------------------------=head2 $pod_para-E<gt>B<file_line()>        my ($filename, $line_number) = $pod_para->file_line();        my $position = $pod_para->file_line();Returns the current filename and line number for the paragraphobject.  If called in an array context, it returns a list of twoelements: first the filename, then the line number. If called ina scalar context, it returns a string containing the filename, followedby a colon (':'), followed by the line number.=cutsub file_line {   my @loc = ($_[0]->{'-file'} || '<unknown-file>',              $_[0]->{'-line'} || 0);   return (wantarray) ? @loc : join(':', @loc);}##---------------------------------------------------------------------------#############################################################################package Pod::InteriorSequence;##---------------------------------------------------------------------------=head1 B<Pod::InteriorSequence>An object representing a POD interior sequence command.It has the following methods/attributes:=cut##---------------------------------------------------------------------------=head2 Pod::InteriorSequence-E<gt>B<new()>        my $pod_seq1 = Pod::InteriorSequence->new(-name => $cmd                                                  -ldelim => $delimiter);        my $pod_seq2 = new Pod::InteriorSequence(-name => $cmd,                                                 -ldelim => $delimiter);        my $pod_seq3 = new Pod::InteriorSequence(-name => $cmd,                                                 -ldelim => $delimiter,                                                 -file => $filename,                                                 -line => $line_number);        my $pod_seq4 = new Pod::InteriorSequence(-name => $cmd, $ptree);        my $pod_seq5 = new Pod::InteriorSequence($cmd, $ptree);This is a class method that constructs a C<Pod::InteriorSequence> objectand returns a reference to the new interior sequence object. It shouldbe given two keyword arguments.  The C<-ldelim> keyword indicates thecorresponding left-delimiter of the interior sequence (e.g. 'E<lt>').The C<-name> keyword indicates the name of the corresponding interiorsequence command, such as C<I> or C<B> or C<C>. The C<-file> andC<-line> keywords indicate the filename and line number correspondingto the beginning of the interior sequence. If the C<$ptree> argument isgiven, it must be the last argument, and it must be either string, orelse an array-ref suitable for passing to B<Pod::ParseTree::new> (orit may be a reference to an Pod::ParseTree object).=cutsub new {    ## Determine if we were called via an object-ref or a classname    my $this = shift;    my $class = ref($this) || $this;    ## See if first argument has no keyword    if (((@_ <= 2) or (@_ % 2)) and $_[0] !~ /^-\w/) {       ## Yup - need an implicit '-name' before first parameter       unshift @_, '-name';    }    ## See if odd number of args    if ((@_ % 2) != 0) {       ## Yup - need an implicit '-ptree' before the last parameter

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -