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

📄 text.pm

📁 Astercon2 开源软交换 2.2.0
💻 PM
📖 第 1 页 / 共 3 页
字号:
# Wrap a line, indenting by the current left margin.  We can't use Text::Wrap# because it plays games with tabs.  We can't use formline, even though we'd# really like to, because it screws up non-printing characters.  So we have to# do the wrapping ourselves.sub wrap {    my $self = shift;    local $_ = shift;    my $output = '';    my $spaces = ' ' x $$self{MARGIN};    my $width = $$self{width} - $$self{MARGIN};    while (length > $width) {        if (s/^([^\n]{0,$width})\s+// || s/^([^\n]{$width})//) {            $output .= $spaces . $1 . "\n";        } else {            last;        }    }    $output .= $spaces . $_;    $output =~ s/\s+$/\n\n/;    $output;}# Reformat a paragraph of text for the current margin.  Takes the text to# reformat and returns the formatted text.sub reformat {    my $self = shift;    local $_ = shift;    # If we're trying to preserve two spaces after sentences, do some munging    # to support that.  Otherwise, smash all repeated whitespace.    if ($$self{sentence}) {        s/ +$//mg;        s/\.\n/. \n/g;        s/\n/ /g;        s/   +/  /g;    } else {        s/\s+/ /g;    }    $self->wrap ($_);}# Output text to the output device.sub output { $_[1] =~ tr/\01/ /; print { $_[0]->output_handle } $_[1] }# Output a block of code (something that isn't part of the POD text).  Called# by preprocess_paragraph only if we were given the code option.  Exists here# only so that it can be overridden by subclasses.sub output_code { $_[0]->output ($_[1]) }############################################################################### 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;        return $parser->parse_from_filehandle (@fhs);    } else {        return $parser->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::Parser, Pod::Text supports the same methods andinterfaces.  See L<Pod::Parser> for all the details; briefly, one creates anew parser with C<< Pod::Text->new() >> and then calls eitherparse_from_filehandle() or parse_from_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::Parser method parse_from_filehandle() takes up to twoarguments, the first being the file handle to read POD from and the secondbeing the file handle to write the formatted output to.  The first defaultsto STDIN if not given, and the second defaults to STDOUT.  The methodparse_from_file() is almost identical, except that its two arguments are theinput and output disk files instead.  See L<Pod::Parser> for the specificdetails.=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.=item %s:%d: Unknown command paragraph: %s(W) The POD source contained a non-standard command paragraph (something ofthe form C<=command args>) that Pod::Man didn't know about.  It was ignored.=item %s:%d: Unknown escape: %s(W) The POD source contained an C<EE<lt>E<gt>> escape that Pod::Text didn'tknow about.=item %s:%d: Unknown formatting code: %s(W) The POD source contained a non-standard formatting code (something ofthe form C<XE<lt>E<gt>>) that Pod::Text didn't know about.=item %s:%d: Unmatched =back(W) Pod::Text encountered a C<=back> command that didn't correspond to anC<=over> command.=back=head1 RESTRICTIONSEmbedded Ctrl-As (octal 001) in the input will be mapped to spaces onoutput, due to an internal implementation detail.=head1 NOTESThis is a replacement for an earlier Pod::Text module written by TomChristiansen.  It has a revamped interface, since it now uses Pod::Parser,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::Parser>, 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>.=head1 COPYRIGHT AND LICENSECopyright 1999, 2000, 2001, 2002 by 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 + -