NAME
CPAN::Search::Lite::Query - perform queries on the database
SYNOPSIS
my $max_results = 200;
my $query = CPAN::Search::Lite::Query->new(db => $db,
user => $user,
passwd => $passwd,
max_results => $max_results);
$query->query(mode => 'module', name => 'Net::FTP');
my $results = $query->{results};
CONSTRUCTING THE QUERY
This module queries the database via various types of queries and returns the results for subsequent display. The CPAN::Search::Lite::Query object is created via the new method as
my $query = CPAN::Search::Lite::Query->new(db => $db,
user => $user,
passwd => $passwd,
max_results => $max_results);
which takes as arguments
db => $db
This is the name of the database.
user => $user
This is the user under which the database connection will be made.
passwd => $passwd
This is the password to use when connecting.
max_results => $max_results
This is the maximum value used to limit the number of results returned under a user query. If not specified, a value contained within
CPAN::Search::Lite::Querywill be used.lang => $lang
This is used to specify what language the description of the CPAN chapter ids and the dslip information is to be returned in. If not specified, or if specified but not present as a key in
%langsofCPAN::Search::Lite::Util, the default ofen(English) will be used.
A basic query then is constructed as
$query->query(mode => $mode, $type => $value);
with the results available as
my $results = $query->{results}
There are four basic modes:
module
This is for information on modules.
dist
This is for information on distributions.
author
This is for information on CPAN authors or cpanids.
chapter
This is for information on chapters associated with distributions and modules.
module, dist, and author modes
For a mode of module, dist, and author, there are four basic options to be used for the $type => $value option:
query => $query_term
This will search through module names and abstracts, distribution names and abstracts, or CPAN author names and full names (for
module,dist, andauthormodes respectively). The results generally are case insensitive. Matches are reported that match all search terms supplied - for example,$query_term = 'foo bar'will find occurences offooandbar. To exclude a term in$query_term, prepend that term with a minus sign =$query_term = 'foo -bar'will find all instancesfoothat don't includebar. Regular expressions (as used bymysql) are also supported.name => $name
This will report exact matches (in a case sensitive manner) for the module name, distribution name, or CPAN author id, for
module,dist, andauthormodes respectively.letter => $letter
If
$letteris a single letter, this will find all modules, distributions, or CPAN author ids beginning with that letter (formodule,dist, andauthormodes respectively). If$letteris more than one letter, this will find all distribtion names matching$letter-*(for thedistmode) or all module names matching$letter::*(for themodulemode).id => $id
This will look up information on the primary key according to the mode specified. This is more for internal use, to help speed up queries; using this "publically" is probably not a good idea, as the ids may change over the course of time.
As well, for the dist mode there is an additional type: recent => $age, which will report all distribtions uploaded in the last $age days. If $age is not specified, it will default to 7.
chapter mode
For a mode of chapter, one can specify three additional arguments:
id => $chapterid
This argument will look up all subchapters with the specified numerical
$chapterid(see%chapsof CPAN::Search::Lite::Util for a description).subchapter => $subchapter
This argument will look up all distributions with the specified
$subchapterwithin the given chapter specified by$chapterid.query => $query_term
This argument will look up all distributions who have a subchapter matching
$query_term.
RESULTS
After making the query, the results can be accessed through
my $results = $query->{results};
No results either can mean no matches were found, or else an error in making the query resulted (in which case, a brief error message is contained in $query->{error}). Assuming there are results, what is returned depends on the mode and on the type of query. See CPAN::Search::Lite::Populate for a description of the fields in the various tables listed below - these fields are used as the keys of the hash references that arise.
author mode
nameoridqueryThis returns the
auth_id,cpanid,email, andfullnameof theauthstable. As well, an array reference$results->{dists}is returned representing all distributions associated with thatcpanid- each member of the array reference is a hash reference describing thedist_id,dist_name,birth,dist_abs,dist_vers, anddist_filefields in thediststable. An additional entry,download, is supplied, which can be used as$CPAN/authors/id/$downloadto specify the url of the distribution.letterqueryThis returns an array reference, each member of which is a hash reference containing the
auth_id,cpanid, andfullnamefields.queryqueryIf this results in more than one match, an array reference is returned, each member of which is a hash reference containg the
auth_id,cpanid, andfullnamefields. If there is only one result found, anamequery based on the matchedcpanidis performed.
module mode
nameoridqueryThis returns the
mod_id,mod_name,mod_abs,doc,mod_vers,dslip,chapterid,dist_id,dist_name,dist_file,auth_id,cpanid, andfullnameof theauths,mods, anddiststables. As well, the following entries may be present.htmlIf
docis true, an entryhtmlis constructed giving the location (relative tohtml_root) of the html file.downloadThis can be used as
$CPAN/authors/id/$downloadto specify the url of the distribution.chap_descAn accompanying entry
chap_descis supplied giving a description ofchapterid, if present. This is given in the language specified, if present, with a default of English.chap_linkAn accompanying entry
chap_linkis supplied giving a string (in English) suitable for use in a link forchapterid, if present.dslip_infoIf
dslipis available, an array referencedslip_infois supplied, each entry being a hash reference. The hash reference contains two keys -desc, whose value is a general description of the what the dslip entry represents, andwhat, whose value is a description of the entry itself.ppmsIf there are ppm packages available for the distribution containing the module, an array reference
ppmsis supplied, each item of which is a hash reference. There are four keys in this hash reference (coming from$repositoriesof CPAN::Search::Lite::Util) -rep_id, giving the repository's rep_id,desc, giving a description of the repository,alias, an alias for the repository, andbrowse, giving a url to the repository.
letterqueryThis returns an array reference, each entry of which can be of two types. If there are multiple occurrences of a module matching
FOO::*at the top level, then the entry is a hash reference with keyletterand associated valueFOO, as well as a keycountwith value giving the number of matching entries. If there is only one module matchingFOO::*at the top level, then the entry is a hash reference containing themod_name,mod_id, andmod_absfields.queryqueryIf this results in more than one match, an array reference is returned, each member of which is a hash reference containing the
mod_id,mod_name, andmod_absfields. If there is only one result found, anamequery based on the matchedmod_nameis performed.
dist mode
nameoridqueryThis returns the
dist_id,dist_name,dist_abs,dist_vers,dist_file,size,birth,readme,changes,meta,install,auth_id,cpanid, andfullnameof theauths,mods, anddiststables. Note thatreadme,changes,meta, andinstallare boolean values just indicating if the corresponding file is present. As well, the following entries may be present.downloadThis can be used as
$CPAN/authors/id/$downloadto specify the url of the distribution.modsThis is an array reference containing information on the modules present. Each entry is a hash reference containing the
mod_id,mod_name,mod_abs,mod_vers,doc, anddslipfields for the module. Ifdocis present, anhtmlentry is created giving the location (relative tohtml_root) of the documentation.dslipanddslip_infoIf the module name and distribution name are related by
s/::/-, thedslipanddslip_infoentries for that module are returned.chapsIf present, an array reference
chapsis returned, each entry of which is a hash reference containingchapterid,subchapter,chap_desc(a description of the chapter id, in the language specified), andchap_link(a string in English suitable for use as a link tochapterid).reqsIf prerequisites for the distribtion have been specified, an array reference
reqsis returned, each item of which is a hash reference containingmod_id,req_vers,mod_name, andmod_absfor each prerequisite.ppmsIf there are ppm packages available for the distribution, an array reference
ppmsis supplied, each item of which is a hash reference. There are three keys in this hash reference (coming from$repositoriesof CPAN::Search::Lite::Util) -rep_id, giving the repository's rep_id,desc, giving a description of the repository, andbrowse, giving a url to the repository.
letterqueryThis returns an array reference, each entry of which can be of two types. If there are multiple occurrences of a distribution matching
FOO-*at the top level, then the entry is a hash reference with keyletterand associated valueFOO, as well as a keycountwith value giving the number of matching entries. If there is only one distribution matchingFOO-*at the top level, then the entry is a hash reference containing thedist_name,dist_id, anddist_absfields.queryqueryIf this results in more than one match, an array reference is returned, each member of which is a hash reference containing the
dist_id,dist_name, anddist_absfields. If there is only one result found, anamequery based on the matcheddist_nameis performed.recentqueryThis performs a query for all distributions uploaded to CPAN in the last 7 days. The result is an array reference, each item of which is a hash reference containing the
birth,dist_id,dist_name,dist_abs,dist_vers,dist_file,auth_id, andcpanidfields. As well, for each entry adownloadentry is present, which can be used as$CPAN/authors/id/$downloadto specify the url of the distribution.
chapter mode
id => $chapterid
This will return an array reference, each item of which is a hash reference containing the corresponding
subchapterfield. If there is only one entry within a subchapter, thedist_absanddist_idof the associated distribution is also returned, while if there is more than one entry, a keycountwith value giving the number of matching entries is returned.subchapter => $subchapter
This will return an array reference corresponding to all distributions with the specified subchapter within the given chapter. Each item of the array reference is a hash reference specifying the
dist_name,dist_id, anddist_absof the distribution.query => $query_term
This will return an array reference, each member of which is a hash reference containing the
dist_id,dist_name,dist_absfields,chapterid, andchap_linkfields. As well, achap_descfield is returned, giving a description of the main chapter.
For a name or id query of dist, author, or module, if the query is constructed as
$query->query(mode => $mode, $type => $value, fields => $fields);
where $fields is an array reference, then only those fields specified will be returned. For author, only the auths table is searched, for module, the mods, auths, and dists tables are searched, and for dist, the dists and auths tables are searched.
SEE ALSO
Apache2::CPAN::Search and Apache2::CPAN::Query.
COPYRIGHT
This software is copyright 2004 by Randy Kobes <randy@theoryx5.uwinnipeg.ca>. Use and redistribution are under the same terms as Perl itself.