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

📄 parser.pm

📁 mrtg 监控,请认真阅读您的文件包然后写出其具体功能
💻 PM
📖 第 1 页 / 共 5 页
字号:
        $_ = $paragraph;  ## save previous contents        if ((! length $paragraph) && ($textline =~ /^==/)) {            ## '==' denotes a one-line command paragraph            $paragraph = $textline;            $plines    = 1;            $textline  = '';        } else {            ## Append this line to the current paragraph            $paragraph .= $textline;            ++$plines;        }        ## See if this line is blank and ends the current paragraph.        ## If it isnt, then keep iterating until it is.        next unless (($textline =~ /^([^\S\r\n]*)[\r\n]*$/)                                     && (length $paragraph));        ## Issue a warning about any non-empty blank lines        if (length($1) > 0 and $myOpts{'-warnings'} and ! $myData{_CUTTING}) {            my $errorsub = $self->errorsub();            my $file = $self->input_file();            my $errmsg = "*** WARNING: line containing nothing but whitespace".                         " in paragraph at line $nlines in file $file\n";            (ref $errorsub) and &{$errorsub}($errmsg)                or (defined $errorsub) and $self->$errorsub($errmsg)                    or  warn($errmsg);        }        ## Now process the paragraph        parse_paragraph($self, $paragraph, ($nlines - $plines) + 1);        $paragraph = '';        $plines = 0;    }    ## Dont forget about the last paragraph in the file    if (length $paragraph) {       parse_paragraph($self, $paragraph, ($nlines - $plines) + 1)    }    ## Now pop the input stream off the top of the input stack.    $self->_pop_input_stream();}##---------------------------------------------------------------------------=head1 B<parse_from_file()>            $parser->parse_from_file($filename,$outfile);This method takes a filename and does the following:=over 2=item *opens the input and output files for reading(creating the appropriate filehandles)=item *invokes the B<parse_from_filehandle()> method passing it thecorresponding input and output filehandles.=item *closes the input and output files.=backIf the special input filename "-" or "<&STDIN" is given then the STDINfilehandle is used for input (and no open or close is performed). If noinput filename is specified then "-" is implied.If a second argument is given then it should be the name of the desiredoutput file. If the special output filename "-" or ">&STDOUT" is giventhen the STDOUT filehandle is used for output (and no open or close isperformed). If the special output filename ">&STDERR" is given then theSTDERR filehandle is used for output (and no open or close isperformed). If no output filehandle is currently in use and no outputfilename is specified, then "-" is implied.This method does I<not> usually need to be overridden by subclasses.=cutsub parse_from_file {    my $self = shift;    my %opts = (ref $_[0] eq 'HASH') ? %{ shift() } : ();    my ($infile, $outfile) = @_;    my ($in_fh,  $out_fh) = (gensym, gensym)  if ($] < 5.6);    my ($close_input, $close_output) = (0, 0);    local *myData = $self;    local $_;    ## Is $infile a filename or a (possibly implied) filehandle    $infile  = '-'  unless ((defined $infile)  && (length $infile));    if (($infile  eq '-') || ($infile =~ /^<&(STDIN|0)$/i)) {        ## Not a filename, just a string implying STDIN        $myData{_INFILE} = "<standard input>";        $in_fh = \*STDIN;    }    elsif (ref $infile) {        ## Must be a filehandle-ref (or else assume its a ref to an object        ## that supports the common IO read operations).        $myData{_INFILE} = ${$infile};        $in_fh = $infile;    }    else {        ## We have a filename, open it for reading        $myData{_INFILE} = $infile;        open($in_fh, "< $infile")  or             croak "Can't open $infile for reading: $!\n";        $close_input = 1;    }    ## NOTE: we need to be *very* careful when "defaulting" the output    ## file. We only want to use a default if this is the beginning of    ## the entire document (but *not* if this is an included file). We    ## determine this by seeing if the input stream stack has been set-up    ## already    ##     unless ((defined $outfile) && (length $outfile)) {        (defined $myData{_TOP_STREAM}) && ($out_fh  = $myData{_OUTPUT})                                       || ($outfile = '-');    }    ## Is $outfile a filename or a (possibly implied) filehandle    if ((defined $outfile) && (length $outfile)) {        if (($outfile  eq '-') || ($outfile =~ /^>&?(?:STDOUT|1)$/i)) {            ## Not a filename, just a string implying STDOUT            $myData{_OUTFILE} = "<standard output>";            $out_fh  = \*STDOUT;        }        elsif ($outfile =~ /^>&(STDERR|2)$/i) {            ## Not a filename, just a string implying STDERR            $myData{_OUTFILE} = "<standard error>";            $out_fh  = \*STDERR;        }        elsif (ref $outfile) {            ## Must be a filehandle-ref (or else assume its a ref to an            ## object that supports the common IO write operations).            $myData{_OUTFILE} = ${$outfile};            $out_fh = $outfile;        }        else {            ## We have a filename, open it for writing            $myData{_OUTFILE} = $outfile;            (-d $outfile) and croak "$outfile is a directory, not POD input!\n";            open($out_fh, "> $outfile")  or                 croak "Can't open $outfile for writing: $!\n";            $close_output = 1;        }    }    ## Whew! That was a lot of work to set up reasonably/robust behavior    ## in the case of a non-filename for reading and writing. Now we just    ## have to parse the input and close the handles when we're finished.    $self->parse_from_filehandle(\%opts, $in_fh, $out_fh);    $close_input  and         close($in_fh) || croak "Can't close $infile after reading: $!\n";    $close_output  and        close($out_fh) || croak "Can't close $outfile after writing: $!\n";}#############################################################################=head1 ACCESSOR METHODSClients of B<Pod::Parser> should use the following methods to accessinstance data fields:=cut##---------------------------------------------------------------------------=head1 B<errorsub()>            $parser->errorsub("method_name");            $parser->errorsub(\&warn_user);            $parser->errorsub(sub { print STDERR, @_ });Specifies the method or subroutine to use when printing error messagesabout POD syntax. The supplied method/subroutine I<must> return TRUE uponsuccessful printing of the message. If C<undef> is given, then the B<warn>builtin is used to issue error messages (this is the default behavior).            my $errorsub = $parser->errorsub()            my $errmsg = "This is an error message!\n"            (ref $errorsub) and &{$errorsub}($errmsg)                or (defined $errorsub) and $parser->$errorsub($errmsg)                    or  warn($errmsg);Returns a method name, or else a reference to the user-supplied subroutineused to print error messages. Returns C<undef> if the B<warn> builtinis used to issue error messages (this is the default behavior).=cutsub errorsub {   return (@_ > 1) ? ($_[0]->{_ERRORSUB} = $_[1]) : $_[0]->{_ERRORSUB};}##---------------------------------------------------------------------------=head1 B<cutting()>            $boolean = $parser->cutting();Returns the current C<cutting> state: a boolean-valued scalar whichevaluates to true if text from the input file is currently being "cut"(meaning it is I<not> considered part of the POD document).            $parser->cutting($boolean);Sets the current C<cutting> state to the given value and returns theresult.=cutsub cutting {   return (@_ > 1) ? ($_[0]->{_CUTTING} = $_[1]) : $_[0]->{_CUTTING};}##---------------------------------------------------------------------------##---------------------------------------------------------------------------=head1 B<parseopts()>When invoked with no additional arguments, B<parseopts> returns a hashtableof all the current parsing options.            ## See if we are parsing non-POD sections as well as POD ones            my %opts = $parser->parseopts();            $opts{'-want_nonPODs}' and print "-want_nonPODs\n";When invoked using a single string, B<parseopts> treats the string as thename of a parse-option and returns its corresponding value if it exists(returns C<undef> if it doesn't).            ## Did we ask to see '=cut' paragraphs?            my $want_cut = $parser->parseopts('-process_cut_cmd');            $want_cut and print "-process_cut_cmd\n";When invoked with multiple arguments, B<parseopts> treats them askey/value pairs and the specified parse-option names are set to thegiven values. Any unspecified parse-options are unaffected.            ## Set them back to the default            $parser->parseopts(-warnings => 0);When passed a single hash-ref, B<parseopts> uses that hash to completelyreset the existing parse-options, all previous parse-option valuesare lost.            ## Reset all options to default             $parser->parseopts( { } );See L<"PARSING OPTIONS"> for more information on the name and meaning of eachparse-option currently recognized.=cutsub parseopts {   local *myData = shift;   local *myOpts = ($myData{_PARSEOPTS} ||= {});   return %myOpts  if (@_ == 0);   if (@_ == 1) {      local $_ = shift;      return  ref($_)  ?  $myData{_PARSEOPTS} = $_  :  $myOpts{$_};   }   my @newOpts = (%myOpts, @_);   $myData{_PARSEOPTS} = { @newOpts };}##---------------------------------------------------------------------------=head1 B<output_file()>            $fname = $parser->output_file();Returns the name of the output file being written.=cutsub output_file {   return $_[0]->{_OUTFILE};}##---------------------------------------------------------------------------=head1 B<output_handle()>            $fhandle = $parser->output_handle();Returns the output filehandle object.=cutsub output_handle {   return $_[0]->{_OUTPUT};}##---------------------------------------------------------------------------=head1 B<input_file()>            $fname = $parser->input_file();Returns the name of the input file being read.=cutsub input_file {   return $_[0]->{_INFILE};}##---------------------------------------------------------------------------=head1 B<input_handle()>            $fhandle = $parser->input_handle();Returns the current input filehandle object.=cutsub input_handle {   return $_[0]->{_INPUT};}##---------------------------------------------------------------------------=begin __PRIVATE__=head1 B<input_streams()>            $listref = $parser->input_streams();Returns a reference to an array which corresponds to the stack of allthe input streams that are currently in the middle of being parsed.While parsing an input stream, it is possible to invokeB<parse_from_file()> or B<parse_from_filehandle()> to parse a new inputstream and then return to parsing the previous input stream. Each inputstream to be parsed is pushed onto the end of this input stackbefore any of its input is read. The input stream that is currentlybeing parsed is always at the end (or top) of the input stack. When aninput stream has been exhausted, it is popped off the end of theinput stack.Each element on this input stack is a reference to C<Pod::InputSource>object. Please see L<Pod::InputObjects> for more details.

⌨️ 快捷键说明

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