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

📄 select.pm

📁 网络监控
💻 PM
📖 第 1 页 / 共 2 页
字号:
}##---------------------------------------------------------------------------=head1 B<add_selection()>            $parser->add_selection($section_spec1,$section_spec2,...);This method is used to add to the currently selected sections andsubsections of POD documentation that are to be printed and/orprocessed. See <select()> for replacing the currently selected sections.Each of the C<$section_spec> arguments should be a section specificationas described in L<"SECTION SPECIFICATIONS">. The section specificationsare parsed by this method and the resulting regular expressions arestored in the invoking object.This method should I<not> normally be overridden by subclasses.=cutsub add_selection {    my $self = shift;    $self->select("+", @_);}##---------------------------------------------------------------------------=head1 B<clear_selections()>            $parser->clear_selections();This method takes no arguments, it has the exact same effect as invoking<select()> with no arguments.=cutsub clear_selections {    my $self = shift;    $self->select();}##---------------------------------------------------------------------------=head1 B<match_section()>            $boolean = $parser->match_section($heading1,$heading2,...);Returns a value of true if the given section and subsection headingtitles match any of the currently selected section specifications ineffect from prior calls to B<select()> and B<add_selection()> (or ifthere are no explictly selected/deselected sections).The arguments C<$heading1>, C<$heading2>, etc. are the heading titles ofthe corresponding sections, subsections, etc. to try and match.  IfC<$headingN> is omitted then it defaults to the current correspondingsection heading title in the input.This method should I<not> normally be overridden by subclasses.=cutsub match_section {    my $self = shift;    my (@headings) = @_;    local *myData = $self;    ## Return true if no restrictions were explicitly specified    my $selections = (exists $myData{_SELECTED_SECTIONS})                       ?  $myData{_SELECTED_SECTIONS}  :  undef;    return  1  unless ((defined $selections) && (@{$selections} > 0));    ## Default any unspecified sections to the current one    my @current_headings = $self->curr_headings();    for (my $i = 0; $i < $MAX_HEADING_LEVEL; ++$i) {        (defined $headings[$i])  or  $headings[$i] = $current_headings[$i];    }    ## Look for a match against the specified section expressions    my ($section_spec, $regex, $negated, $match);    for $section_spec ( @{$selections} ) {        ##------------------------------------------------------        ## Each portion of this spec must match in order for        ## the spec to be matched. So we will start with a         ## match-value of 'true' and logically 'and' it with        ## the results of matching a given element of the spec.        ##------------------------------------------------------        $match = 1;        for (my $i = 0; $i < $MAX_HEADING_LEVEL; ++$i) {            $regex   = $section_spec->[$i];            $negated = ($regex =~ s/^\!//);            $match  &= ($negated ? ($headings[$i] !~ /${regex}/)                                 : ($headings[$i] =~ /${regex}/));            last unless ($match);        }        return  1  if ($match);    }    return  0;  ## no match}##---------------------------------------------------------------------------=head1 B<is_selected()>            $boolean = $parser->is_selected($paragraph);This method is used to determine if the block of text given inC<$paragraph> falls within the currently selected set of POD sectionsand subsections to be printed or processed. This method is alsoresponsible for keeping track of the current input section andsubsections. It is assumed that C<$paragraph> is the most recently read(but not yet processed) input paragraph.The value returned will be true if the C<$paragraph> and the rest of thetext in the same section as C<$paragraph> should be selected (included)for processing; otherwise a false value is returned.=cutsub is_selected {    my ($self, $paragraph) = @_;    local $_;    local *myData = $self;    $self->_init_headings()  unless (defined $myData{_SECTION_HEADINGS});    ## Keep track of current sections levels and headings    $_ = $paragraph;    if (/^=((?:sub)*)(?:head(?:ing)?|sec(?:tion)?)(\d*)\s+(.*)\s*$/) {        ## This is a section heading command        my ($level, $heading) = ($2, $3);        $level = 1 + (length($1) / 3)  if ((! length $level) || (length $1));        ## Reset the current section heading at this level        $myData{_SECTION_HEADINGS}->[$level - 1] = $heading;        ## Reset subsection headings of this one to empty        for (my $i = $level; $i < $MAX_HEADING_LEVEL; ++$i) {            $myData{_SECTION_HEADINGS}->[$i] = '';        }    }    return  $self->match_section();}#############################################################################=head1 EXPORTED FUNCTIONSThe following functions are exported by this module. Please note thatthese are functions (not methods) and therefore C<do not> take animplicit first argument.=cut##---------------------------------------------------------------------------=head1 B<podselect()>            podselect(\%options,@filelist);B<podselect> will print the raw (untranslated) POD paragraphs of allPOD sections in the given input files specified by C<@filelist>according to the given options.If any argument to B<podselect> is a reference to a hash(associative array) then the values with the following keys areprocessed as follows:=over 4=item B<-output>A string corresponding to the desired output file (or ">&STDOUT"or ">&STDERR"). The default is to use standard output.=item B<-sections>A reference to an array of sections specifications (as described inL<"SECTION SPECIFICATIONS">) which indicate the desired set of PODsections and subsections to be selected from input. If no sectionspecifications are given, then all sections of the PODs are used.=begin _NOT_IMPLEMENTED_=item B<-ranges>A reference to an array of range specifications (as described inL<"RANGE SPECIFICATIONS">) which indicate the desired range of PODparagraphs to be selected from the desired input sections. If no rangespecifications are given, then all paragraphs of the desired sectionsare used.=end _NOT_IMPLEMENTED_=backAll other arguments should correspond to the names of input filescontaining POD sections. A file name of "-" or "<&STDIN" willbe interpeted to mean standard input (which is the default if nofilenames are given).=cut sub podselect {    my(@argv) = @_;    my %defaults   = ();    my $pod_parser = new Pod::Select(%defaults);    my $num_inputs = 0;    my $output = ">&STDOUT";    my %opts = ();    local $_;    for (@argv) {        if (ref($_)) {            next unless (ref($_) eq 'HASH');            %opts = (%defaults, %{$_});            ##-------------------------------------------------------------            ## Need this for backward compatibility since we formerly used            ## options that were all uppercase words rather than ones that            ## looked like Unix command-line options.            ## to be uppercase keywords)            ##-------------------------------------------------------------            %opts = map {                my ($key, $val) = (lc $_, $opts{$_});                $key =~ s/^(?=\w)/-/;                $key =~ /^-se[cl]/  and  $key  = '-sections';                #! $key eq '-range'    and  $key .= 's';                ($key => $val);                } (keys %opts);            ## Process the options            (exists $opts{'-output'})  and  $output = $opts{'-output'};            ## Select the desired sections            $pod_parser->select(@{ $opts{'-sections'} })                if ( (defined $opts{'-sections'})                     && ((ref $opts{'-sections'}) eq 'ARRAY') );            #! ## Select the desired paragraph ranges            #! $pod_parser->select(@{ $opts{'-ranges'} })            #!     if ( (defined $opts{'-ranges'})            #!          && ((ref $opts{'-ranges'}) eq 'ARRAY') );        }        else {            $pod_parser->parse_from_file($_, $output);            ++$num_inputs;        }    }    $pod_parser->parse_from_file("-")  unless ($num_inputs > 0);}#############################################################################=head1 PRIVATE METHODS AND DATAB<Pod::Select> makes uses a number of internal methods and data fieldswhich clients should not need to see or use. For the sake of avoidingname collisions with client data and methods, these methods and fieldsare briefly discussed here. Determined hackers may obtain furtherinformation about them by reading the B<Pod::Select> source code.Private data fields are stored in the hash-object whose reference isreturned by the B<new()> constructor for this class. The names of allprivate methods and data-fields used by B<Pod::Select> begin with aprefix of "_" and match the regular expression C</^_\w+$/>.=cut##---------------------------------------------------------------------------=begin _PRIVATE_=head1 B<_compile_section_spec()>            $listref = $parser->_compile_section_spec($section_spec);This function (note it is a function and I<not> a method) takes asection specification (as described in L<"SECTION SPECIFICATIONS">)given in C<$section_sepc>, and compiles it into a list of regularexpressions. If C<$section_spec> has no syntax errors, then a referenceto the list (array) of corresponding regular expressions is returned;otherwise C<undef> is returned and an error message is printed (usingB<carp>) for each invalid regex.=end _PRIVATE_=cutsub _compile_section_spec {    my ($section_spec) = @_;    my (@regexs, $negated);    ## Compile the spec into a list of regexs    local $_ = $section_spec;    s|\\\\|\001|g;  ## handle escaped backward slashes    s|\\/|\002|g;   ## handle escaped forward slashes    ## Parse the regexs for the heading titles    @regexs = split('/', $_, $MAX_HEADING_LEVEL);    ## Set default regex for ommitted levels    for (my $i = 0; $i < $MAX_HEADING_LEVEL; ++$i) {        $regexs[$i]  = '.*'  unless ((defined $regexs[$i])                                     && (length $regexs[$i]));    }    ## Modify the regexs as needed and validate their syntax    my $bad_regexs = 0;    for (@regexs) {        $_ .= '.+'  if ($_ eq '!');        s|\001|\\\\|g;       ## restore escaped backward slashes        s|\002|\\/|g;        ## restore escaped forward slashes        $negated = s/^\!//;  ## check for negation        eval "/$_/";         ## check regex syntax        if ($@) {            ++$bad_regexs;            carp "Bad regular expression /$_/ in \"$section_spec\": $@\n";        }        else {            ## Add the forward and rear anchors (and put the negator back)            $_ = '^' . $_  unless (/^\^/);            $_ = $_ . '$'  unless (/\$$/);            $_ = '!' . $_  if ($negated);        }    }    return  (! $bad_regexs) ? [ @regexs ] : undef;}##---------------------------------------------------------------------------=begin _PRIVATE_=head2 $self->{_SECTION_HEADINGS}A reference to an array of the current section heading titles for eachheading level (note that the first heading level title is at index 0).=end _PRIVATE_=cut##---------------------------------------------------------------------------=begin _PRIVATE_=head2 $self->{_SELECTED_SECTIONS}A reference to an array of references to arrays. Each subarray is a listof anchored regular expressions (preceded by a "!" if the expression is tobe negated). The index of the expression in the subarray should correspondto the index of the heading title in C<$self-E<gt>{_SECTION_HEADINGS}>that it is to be matched against.=end _PRIVATE_=cut#############################################################################=head1 SEE ALSOL<Pod::Parser>=head1 AUTHORBrad Appleton E<lt>bradapp@enteract.comE<gt>Based on code for B<pod2text> written byTom Christiansen E<lt>tchrist@mox.perl.comE<gt>=cut1;

⌨️ 快捷键说明

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