📄 search.pm
字号:
=head1 NAMEPod::Simple::Search - find POD documents in directory trees=head1 SYNOPSIS use Pod::Simple::Search; my $name2path = Pod::Simple::Search->new->limit_glob('LWP::*')->survey; print "Looky see what I found: ", join(' ', sort keys %$name2path), "\n"; print "LWPUA docs = ", Pod::Simple::Search->new->find('LWP::UserAgent') || "?", "\n";=head1 DESCRIPTIONB<Pod::Simple::Search> is a class that you use for running searchesfor Pod files. An object of this class has several attributes(mostly options for controlling search options), and some methodsfor searching based on those attributes.The way to use this class is to make a new object of this class,set any options, and then call one of the search options(probably C<survey> or C<find>). The sections below discuss thesyntaxes for doing all that.=head1 CONSTRUCTORThis class provides the one constructor, called C<new>.It takes no parameters: use Pod::Simple::Search; my $search = Pod::Simple::Search->new;=head1 ACCESSORSThis class defines several methods for setting (and, occasionally,reading) the contents of an object. With two exceptions (discussed atthe end of this section), these attributes are just for controlling theway searches are carried out.Note that each of these return C<$self> when you call them asC<< $self->I<whatever(value)> >>. That's so that you can chaintogether set-attribute calls like this: my $name2path = Pod::Simple::Search->new -> inc(0) -> verbose(1) -> callback(\&blab) ->survey(@there);...which works exactly as if you'd done this: my $search = Pod::Simple::Search->new; $search->inc(0); $search->verbose(1); $search->callback(\&blab); my $name2path = $search->survey(@there);=over=item $search->inc( I<true-or-false> );This attribute, if set to a true value, means that searches shouldimplicitly add perl's I<@INC> paths. Thisautomatically considers paths specified in the C<PERL5LIB> environmentas this is prepended to I<@INC> by the Perl interpreter itself.This attribute's default value is B<TRUE>. If you want to searchonly specific directories, set $self->inc(0) before calling$inc->survey or $inc->find.=item $search->verbose( I<nonnegative-number> );This attribute, if set to a nonzero positive value, will make searches output(via C<warn>) notes about what they're doing as they do it.This option may be useful for debugging a pod-related module.This attribute's default value is zero, meaning that no C<warn> messagesare produced. (Setting verbose to 1 turns on some messages, and settingit to 2 turns on even more messages, i.e., makes the following search(es)even more verbose than 1 would make them.)=item $search->limit_glob( I<some-glob-string> );This option means that you want to limit the results just to items whosepodnames match the given glob/wildcard expression. For example, youmight limit your search to just "LWP::*", to search only for modulesstarting with "LWP::*" (but not including the module "LWP" itself); oryou might limit your search to "LW*" to see only modules whose (full)names begin with "LW"; or you might search for "*Find*" to search forall modules with "Find" somewhere in their full name. (You can also use"?" in a glob expression; so "DB?" will match "DBI" and "DBD".)=item $search->callback( I<\&some_routine> );This attribute means that every time this search sees a matchingPod file, it should call this callback routine. The routine is calledwith two parameters: the current file's filespec, and its pod name.(For example: C<("/etc/perljunk/File/Crunk.pm", "File::Crunk")> wouldbe in C<@_>.)The callback routine's return value is not used for anything.This attribute's default value is false, meaning that no callbackis called.=item $search->laborious( I<true-or-false> );Unless you set this attribute to a true value, Pod::Search will apply Perl-specific heuristics to find the correct module PODs quickly.This attribute's default value is false. You won't normally needto set this to true.Specifically: Turning on this option will disable the heuristics forseeing only files with Perl-like extensions, omitting subdirectoriesthat are numeric but do I<not> match the current Perl interpreter'sversion ID, suppressing F<site_perl> as a module hierarchy name, etc.=item $search->shadows( I<true-or-false> );Unless you set this attribute to a true value, Pod::Simple::Search willconsider only the first file of a given modulename as it looks thru thespecified directories; that is, with this option off, ifPod::Simple::Search has seen a C<somepathdir/Foo/Bar.pm> already in thissearch, then it won't bother looking at a C<somelaterpathdir/Foo/Bar.pm>later on in that search, because that file is merely a "shadow". But ifyou turn on C<< $self->shadows(1) >>, then these "shadow" files areinspected too, and are noted in the pathname2podname return hash.This attribute's default value is false; and normally you won'tneed to turn it on.=item $search->limit_re( I<some-regxp> );Setting this attribute (to a value that's a regexp) means that you wantto limit the results just to items whose podnames match the givenregexp. Normally this option is not needed, and the more efficientC<limit_glob> attribute is used instead.=item $search->dir_prefix( I<some-string-value> );Setting this attribute to a string value means that the searches shouldbegin in the specified subdirectory name (like "Pod" or "File::Find",also expressable as "File/Find"). For example, the search optionC<< $search->limit_glob("File::Find::R*") >>is the same as the combination of the search optionsC<< $search->limit_re("^File::Find::R") -> dir_prefix("File::Find") >>.Normally you don't need to know about the C<dir_prefix> option, but Iinclude it in case it might prove useful for someone somewhere.(Implementationally, searching with limit_glob ends up setting limit_reand usually dir_prefix.)=item $search->progress( I<some-progress-object> );If you set a value for this attribute, the value is expectedto be an object (probably of a class that you define) that has a C<reach> method and a C<done> method. This is meant for reportingprogress during the search, if you don't want to use a simplecallback.Normally you don't need to know about the C<progress> option, but Iinclude it in case it might prove useful for someone somewhere.While a search is in progress, the progress object's C<reach> andC<done> methods are called like this: # Every time a file is being scanned for pod: $progress->reach($count, "Scanning $file"); ++$count; # And then at the end of the search: $progress->done("Noted $count Pod files total");Internally, we often set this to an object of classPod::Simple::Progress. That class is probably undocumented,but you may wish to look at its source.=item $name2path = $self->name2path;This attribute is not a search parameter, but is used to report theresult of C<survey> method, as discussed in the next section.=item $path2name = $self->path2name;This attribute is not a search parameter, but is used to report theresult of C<survey> method, as discussed in the next section.=back=head1 MAIN SEARCH METHODSOnce you've actually set any options you want (if any), you can goahead and use the following methods to search for Pod filesin particular ways.=head2 C<< $search->survey( @directories ) >>The method C<survey> searches for POD documents in a given set offiles and/or directories. This runs the search according to the variousoptions set by the accessors above. (For example, if the C<inc> attributeis on, as it is by default, then the perl @INC directories are implicitlyadded to the list of directories (if any) that you specify.)The return value of C<survey> is two hashes:=over=item C<name2path>A hash that maps from each pod-name to the filespec (like"Stuff::Thing" => "/whatever/plib/Stuff/Thing.pm")=item C<path2name>A hash that maps from each Pod filespec to its pod-name (like"/whatever/plib/Stuff/Thing.pm" => "Stuff::Thing")=backBesides saving these hashes as the hashref attributesC<name2path> and C<path2name>, calling this function also returnsthese hashrefs. In list context, the return value ofC<< $search->survey >> is the list C<(\%name2path, \%path2name)>.In scalar context, the return value is C<\%name2path>.Or you can just call this in void context.Regardless of calling context, calling C<survey> savesits results in its C<name2path> and C<path2name> attributes.E.g., when searching in F<$HOME/perl5lib>, the fileF<$HOME/perl5lib/MyModule.pm> would get the POD name I<MyModule>,whereas F<$HOME/perl5lib/Myclass/Subclass.pm> would beI<Myclass::Subclass>. The name information can be used for PODtranslators.Only text files containing at least one valid POD command are found.In verbose mode, a warning is printed if shadows are found (i.e., morethan one POD file with the same POD name is found, e.g. F<CPAN.pm> indifferent directories). This usually indicates duplicate occurrences ofmodules in the I<@INC> search path, which is occasionally inadvertent(but is often simply a case of a user's path dir having a more recentversion than the system's general path dirs in general.)The options to this argument is a list of either directories that aresearched recursively, or files. (Usually you wouldn't specify files,but just dirs.) Or you can just specify an empty-list, as in$name2path; with theC<inc> option on, as it is by default, tehThe POD names of files are the plain basenames with any Perl-likeextension (.pm, .pl, .pod) stripped, and path separators replaced byC<::>'s.Calling Pod::Simple::Search->search(...) is short forPod::Simple::Search->new->search(...). That is, a throwaway objectwith default attribute values is used.=head2 C<< $search->simplify_name( $str ) >>The method B<simplify_name> is equivalent to B<basename>, but alsostrips Perl-like extensions (.pm, .pl, .pod) and extensions likeF<.bat>, F<.cmd> on Win32 and OS/2, or F<.com> on VMS, respectively.=head2 C<< $search->find( $pod ) >>=head2 C<< $search->find( $pod, @search_dirs ) >>Returns the location of a Pod file, given a Pod/module/script name(like "Foo::Bar" or "perlvar" or "perldoc"), and an idea ofwhat files/directories to look in.It searches according to the various options set by the accessors above.(For example, if the C<inc> attribute is on, as it is by default, thenthe perl @INC directories are implicitly added to the list ofdirectories (if any) that you specify.)This returns the full path of the first occurrence to the file.Package names (eg 'A::B') are automatically converted to directorynames in the selected directory. Additionally, '.pm', '.pl' and '.pod'are automatically appended to the search as required.(So, for example, under Unix, "A::B" is converted to "somedir/A/B.pm","somedir/A/B.pod", or "somedir/A/B.pl", as appropriate.)If no such Pod file is found, this method returns undef.If any of the given search directories contains a F<pod/> subdirectory,then it is searched. (That's how we manage to find F<perlfunc>,for example, which is usually in F<pod/perlfunc> in most Perl dists.)The C<verbose> and C<inc> attributes influence the behavior of thissearch; notably, C<inc>, if true, adds @INC I<and also$Config::Config{'scriptdir'}> to the list of directories to search.It is common to simply say C<< $filename = Pod::Simple::Search-> new ->find("perlvar") >> so that just the @INC (well, and scriptdir)directories are searched. (This happens because the C<inc>attribute is true by default.)Calling Pod::Simple::Search->find(...) is short forPod::Simple::Search->new->find(...). That is, a throwaway objectwith default attribute values is used.=head2 C<< $self->contains_pod( $file ) >>Returns true if the supplied filename (not POD module) contains some Poddocumentation.=head1 AUTHORSean M. Burke E<lt>sburke@cpan.orgE<gt>borrowed code fromMarek Rouchal's Pod::Find, which in turnheavily borrowed code from Nick Ing-Simmons' PodToHtml.Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt> providedC<find> and C<contains_pod> to Pod::Find.=head1 SEE ALSOL<Pod::Simple>, L<Pod::Perldoc>=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -