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

📄 text.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
    my ($self, $attrs, $text) = @_;    $self->heading ($text, $$self{opt_indent} / 2, '==  ');}# Third level heading.sub cmd_head3 {    my ($self, $attrs, $text) = @_;    $self->heading ($text, $$self{opt_indent} * 2 / 3 + 0.5, '=   ');}# Fourth level heading.sub cmd_head4 {    my ($self, $attrs, $text) = @_;    $self->heading ($text, $$self{opt_indent} * 3 / 4 + 0.5, '-   ');}############################################################################### List handling############################################################################### Handle the beginning of an =over block.  Takes the type of the block as the# first argument, and then the attr hash.  This is called by the handlers for# the four different types of lists (bullet, number, text, and block).sub over_common_start {    my ($self, $attrs) = @_;    $self->item ("\n\n") if defined $$self{ITEM};    # Find the indentation level.    my $indent = $$attrs{indent};    unless (defined ($indent) && $indent =~ /^\s*[-+]?\d{1,4}\s*$/) {        $indent = $$self{opt_indent};    }    # Add this to our stack of indents and increase our current margin.    push (@{ $$self{INDENTS} }, $$self{MARGIN});    $$self{MARGIN} += ($indent + 0);    return '';}# End an =over block.  Takes no options other than the class pointer.  Output# any pending items and then pop one level of indentation.sub over_common_end {    my ($self) = @_;    $self->item ("\n\n") if defined $$self{ITEM};    $$self{MARGIN} = pop @{ $$self{INDENTS} };    return '';}# Dispatch the start and end calls as appropriate.sub start_over_bullet { $_[0]->over_common_start ($_[1]) }sub start_over_number { $_[0]->over_common_start ($_[1]) }sub start_over_text   { $_[0]->over_common_start ($_[1]) }sub start_over_block  { $_[0]->over_common_start ($_[1]) }sub end_over_bullet { $_[0]->over_common_end }sub end_over_number { $_[0]->over_common_end }sub end_over_text   { $_[0]->over_common_end }sub end_over_block  { $_[0]->over_common_end }# The common handler for all item commands.  Takes the type of the item, the# attributes, and then the text of the item.sub item_common {    my ($self, $type, $attrs, $text) = @_;    $self->item if defined $$self{ITEM};    # Clean up the text.  We want to end up with two variables, one ($text)    # which contains any body text after taking out the item portion, and    # another ($item) which contains the actual item text.  Note the use of    # the internal Pod::Simple attribute here; that's a potential land mine.    $text =~ s/\s+$//;    my ($item, $index);    if ($type eq 'bullet') {        $item = '*';    } elsif ($type eq 'number') {        $item = $$attrs{'~orig_content'};    } else {        $item = $text;        $item =~ s/\s*\n\s*/ /g;        $text = '';    }    $$self{ITEM} = $item;    # If body text for this item was included, go ahead and output that now.    if ($text) {        $text =~ s/\s*$/\n/;        $self->item ($text);    }    return '';}# Dispatch the item commands to the appropriate place.sub cmd_item_bullet { my $self = shift; $self->item_common ('bullet', @_) }sub cmd_item_number { my $self = shift; $self->item_common ('number', @_) }sub cmd_item_text   { my $self = shift; $self->item_common ('text',   @_) }sub cmd_item_block  { my $self = shift; $self->item_common ('block',  @_) }############################################################################### Formatting codes############################################################################### The simple ones.sub cmd_b { return $_[0]{alt} ? "``$_[2]''" : $_[2] }sub cmd_f { return $_[0]{alt} ? "\"$_[2]\"" : $_[2] }sub cmd_i { return '*' . $_[2] . '*' }sub cmd_x { return '' }# Apply a whole bunch of messy heuristics to not quote things that don't# benefit from being quoted.  These originally come from Barrie Slaymaker and# largely duplicate code in Pod::Man.sub cmd_c {    my ($self, $attrs, $text) = @_;    # A regex that matches the portion of a variable reference that's the    # array or hash index, separated out just because we want to use it in    # several places in the following regex.    my $index = '(?: \[.*\] | \{.*\} )?';    # Check for things that we don't want to quote, and if we find any of    # them, return the string with just a font change and no quoting.    $text =~ m{      ^\s*      (?:         ( [\'\`\"] ) .* \1                             # already quoted       | \` .* \'                                       # `quoted'       | \$+ [\#^]? \S $index                           # special ($^Foo, $")       | [\$\@%&*]+ \#? [:\'\w]+ $index                 # plain var or func       | [\$\@%&*]* [:\'\w]+ (?: -> )? \(\s*[^\s,]\s*\) # 0/1-arg func call       | [+-]? ( \d[\d.]* | \.\d+ ) (?: [eE][+-]?\d+ )? # a number       | 0x [a-fA-F\d]+                                 # a hex constant      )      \s*\z     }xo && return $text;    # If we didn't return, go ahead and quote the text.    return $$self{opt_alt}        ? "``$text''"        : "$$self{LQUOTE}$text$$self{RQUOTE}";}# Links reduce to the text that we're given, wrapped in angle brackets if it's# a URL.sub cmd_l {    my ($self, $attrs, $text) = @_;    return $$attrs{type} eq 'url' ? "<$text>" : $text;}############################################################################### Backwards compatibility############################################################################### The old Pod::Text module did everything in a pod2text() function.  This# tries to provide the same interface for legacy applications.sub pod2text {    my @args;    # This is really ugly; I hate doing option parsing in the middle of a    # module.  But the old Pod::Text module supported passing flags to its    # entry function, so handle -a and -<number>.    while ($_[0] =~ /^-/) {        my $flag = shift;        if    ($flag eq '-a')       { push (@args, alt => 1)    }        elsif ($flag =~ /^-(\d+)$/) { push (@args, width => $1) }        else {            unshift (@_, $flag);            last;        }    }    # Now that we know what arguments we're using, create the parser.    my $parser = Pod::Text->new (@args);    # If two arguments were given, the second argument is going to be a file    # handle.  That means we want to call parse_from_filehandle(), which means    # we need to turn the first argument into a file handle.  Magic open will    # handle the <&STDIN case automagically.    if (defined $_[1]) {        my @fhs = @_;        local *IN;        unless (open (IN, $fhs[0])) {            croak ("Can't open $fhs[0] for reading: $!\n");            return;        }        $fhs[0] = \*IN;        $parser->output_fh ($fhs[1]);        my $retval = $parser->parse_file ($fhs[0]);        my $fh = $parser->output_fh ();        close $fh;        return $retval;    } else {        return $parser->parse_file (@_);    }}# Reset the underlying Pod::Simple object between calls to parse_from_file so# that the same object can be reused to convert multiple pages.sub parse_from_file {    my $self = shift;    $self->reinit;    # Fake the old cutting option to Pod::Parser.  This fiddings with internal    # Pod::Simple state and is quite ugly; we need a better approach.    if (ref ($_[0]) eq 'HASH') {        my $opts = shift @_;        if (defined ($$opts{-cutting}) && !$$opts{-cutting}) {            $$self{in_pod} = 1;            $$self{last_was_blank} = 1;        }    }    # Do the work.    my $retval = $self->Pod::Simple::parse_from_file (@_);    # Flush output, since Pod::Simple doesn't do this.  Ideally we should also    # close the file descriptor if we had to open one, but we can't easily    # figure this out.    my $fh = $self->output_fh ();    my $oldfh = select $fh;    my $oldflush = $|;    $| = 1;    print $fh '';    $| = $oldflush;    select $oldfh;    return $retval;}# Pod::Simple failed to provide this backward compatibility function, so# implement it ourselves.  File handles are one of the inputs that# parse_from_file supports.sub parse_from_filehandle {    my $self = shift;    $self->parse_from_file (@_);}############################################################################### Module return value and documentation##############################################################################1;__END__=head1 NAMEPod::Text - Convert POD data to formatted ASCII text=head1 SYNOPSIS    use Pod::Text;    my $parser = Pod::Text->new (sentence => 0, width => 78);    # Read POD from STDIN and write to STDOUT.    $parser->parse_from_filehandle;    # Read POD from file.pod and write to file.txt.    $parser->parse_from_file ('file.pod', 'file.txt');=head1 DESCRIPTIONPod::Text is a module that can convert documentation in the POD format (thepreferred language for documenting Perl) into formatted ASCII.  It uses nospecial formatting controls or codes whatsoever, and its output is thereforesuitable for nearly any device.As a derived class from Pod::Simple, Pod::Text supports the same methods andinterfaces.  See L<Pod::Simple> for all the details; briefly, one creates anew parser with C<< Pod::Text->new() >> and then normally calls parse_file().new() can take options, in the form of key/value pairs, that control thebehavior of the parser.  The currently recognized options are:=over 4=item altIf set to a true value, selects an alternate output format that, among otherthings, uses a different heading style and marks C<=item> entries with acolon in the left margin.  Defaults to false.=item codeIf set to a true value, the non-POD parts of the input file will be includedin the output.  Useful for viewing code documented with POD blocks with thePOD rendered and the code left intact.=item indentThe number of spaces to indent regular text, and the default indentation forC<=over> blocks.  Defaults to 4.=item looseIf set to a true value, a blank line is printed after a C<=head1> heading.If set to false (the default), no blank line is printed after C<=head1>,although one is still printed after C<=head2>.  This is the default becauseit's the expected formatting for manual pages; if you're formattingarbitrary text documents, setting this to true may result in more pleasingoutput.=item marginThe width of the left margin in spaces.  Defaults to 0.  This is the marginfor all text, including headings, not the amount by which regular text isindented; for the latter, see the I<indent> option.  To set the rightmargin, see the I<width> option.=item quotesSets the quote marks used to surround CE<lt>> text.  If the value is asingle character, it is used as both the left and right quote; if it is twocharacters, the first character is used as the left quote and the second asthe right quoted; and if it is four characters, the first two are used asthe left quote and the second two as the right quote.This may also be set to the special value C<none>, in which case no quotemarks are added around CE<lt>> text.=item sentenceIf set to a true value, Pod::Text will assume that each sentence ends in twospaces, and will try to preserve that spacing.  If set to false, allconsecutive whitespace in non-verbatim paragraphs is compressed into asingle space.  Defaults to true.=item widthThe column at which to wrap text on the right-hand side.  Defaults to 76.=backThe standard Pod::Simple method parse_file() takes one argument, the file orfile handle to read from, and writes output to standard output unless thathas been changed with the output_fh() method.  See L<Pod::Simple> for thespecific details and for other alternative interfaces.=head1 DIAGNOSTICS=over 4=item Bizarre space in item=item Item called without tag(W) Something has gone wrong in internal C<=item> processing.  Thesemessages indicate a bug in Pod::Text; you should never see them.=item Can't open %s for reading: %s(F) Pod::Text was invoked via the compatibility mode pod2text() interfaceand the input file it was given could not be opened.=item Invalid quote specification "%s"(F) The quote specification given (the quotes option to the constructor) wasinvalid.  A quote specification must be one, two, or four characters long.=back=head1 NOTESThis is a replacement for an earlier Pod::Text module written by TomChristiansen.  It has a revamped interface, since it now uses Pod::Simple,but an interface roughly compatible with the old Pod::Text::pod2text()function is still available.  Please change to the new calling convention,though.The original Pod::Text contained code to do formatting via termcapsequences, although it wasn't turned on by default and it was problematic toget it to work at all.  This rewrite doesn't even try to do that, but asubclass of it does.  Look for L<Pod::Text::Termcap>.=head1 SEE ALSOL<Pod::Simple>, L<Pod::Text::Termcap>, L<pod2text(1)>The current version of this module is always available from its web site atL<http://www.eyrie.org/~eagle/software/podlators/>.  It is also part of thePerl core distribution as of 5.6.0.=head1 AUTHORRuss Allbery <rra@stanford.edu>, based I<very> heavily on the originalPod::Text by Tom Christiansen <tchrist@mox.perl.com> and its conversion toPod::Parser by Brad Appleton <bradapp@enteract.com>.  Sean Burke's initialconversion of Pod::Man to use Pod::Simple provided much-needed guidance onhow to use Pod::Simple.=head1 COPYRIGHT AND LICENSECopyright 1999, 2000, 2001, 2002, 2004, 2006 Russ Allbery <rra@stanford.edu>.This program is free software; you may redistribute it and/or modify itunder the same terms as Perl itself.=cut

⌨️ 快捷键说明

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