?? backend.pm
字號:
package CPANPLUS::Backend;use strict;use CPANPLUS::Error;use CPANPLUS::Configure;use CPANPLUS::Internals;use CPANPLUS::Internals::Constants;use CPANPLUS::Module;use CPANPLUS::Module::Author;use CPANPLUS::Backend::RV;use FileHandle;use File::Spec ();use File::Spec::Unix ();use Params::Check qw[check];use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';$Params::Check::VERBOSE = 1;use vars qw[@ISA $VERSION];@ISA = qw[CPANPLUS::Internals];$VERSION = $CPANPLUS::Internals::VERSION;### mark that we're running under CPANPLUS to spawned processes$ENV{'PERL5_CPANPLUS_IS_RUNNING'} = $$;### XXX version.pm MAY format this version, if it's in use... :(### so for consistency, just call ->VERSION ourselves as well.$ENV{'PERL5_CPANPLUS_IS_VERSION'} = __PACKAGE__->VERSION;=pod=head1 NAMECPANPLUS::Backend=head1 SYNOPSIS my $cb = CPANPLUS::Backend->new; my $conf = $cb->configure_object; my $author = $cb->author_tree('KANE'); my $mod = $cb->module_tree('Some::Module'); my $mod = $cb->parse_module( module => 'Some::Module' ); my @objs = $cb->search( type => TYPE, allow => [...] ); $cb->flush('all'); $cb->reload_indices; $cb->local_mirror;=head1 DESCRIPTIONThis module provides the programmer's interface to the C<CPANPLUS>libraries.=head1 ENVIRONMENTWhen C<CPANPLUS::Backend> is loaded, which is necessary for justabout every <CPANPLUS> operation, the environment variableC<PERL5_CPANPLUS_IS_RUNNING> is set to the current process id.Additionally, the environment variable C<PERL5_CPANPLUS_IS_VERSION> will be set to the version of C<CPANPLUS::Backend>.This information might be useful somehow to spawned processes.=head1 METHODS=head2 $cb = CPANPLUS::Backend->new( [CONFIGURE_OBJ] )This method returns a new C<CPANPLUS::Backend> object.This also initialises the config corresponding to this object.You have two choices in this:=over 4=item Provide a valid C<CPANPLUS::Configure> objectThis will be used verbatim.=item No argumentsYour default config will be loaded and used.=backNew will return a C<CPANPLUS::Backend> object on success and die onfailure.=cutsub new { my $class = shift; my $conf; if( $_[0] && IS_CONFOBJ->( conf => $_[0] ) ) { $conf = shift; } else { $conf = CPANPLUS::Configure->new() or return; } my $self = $class->SUPER::_init( _conf => $conf ); return $self;}=pod=head2 $href = $cb->module_tree( [@modules_names_list] )Returns a reference to the CPANPLUS module tree.If you give it any arguments, they will be treated as module namesand C<module_tree> will try to look up these module names andreturn the corresponding module objects instead.See L<CPANPLUS::Module> for the operations you can perform on amodule object.=cutsub module_tree { my $self = shift; my $modtree = $self->_module_tree; if( @_ ) { my @rv; for my $name ( grep { defined } @_) { ### From John Malmberg: This is failing on VMS ### because ODS-2 does not retain the case of ### filenames that are created. ### The problem is the filename is being converted ### to a module name and then looked up in the ### %$modtree hash. ### ### As a fix, we do a search on VMS instead -- ### more cpu cycles, but it gets around the case ### problem --kane my ($modobj) = do { ON_VMS ? $self->search( type => 'module', allow => [qr/^$name$/i], ) : $modtree->{$name} }; push @rv, $modobj || ''; } return @rv == 1 ? $rv[0] : @rv; } else { return $modtree; }}=pod=head2 $href = $cb->author_tree( [@author_names_list] )Returns a reference to the CPANPLUS author tree.If you give it any arguments, they will be treated as author namesand C<author_tree> will try to look up these author names andreturn the corresponding author objects instead.See L<CPANPLUS::Module::Author> for the operations you can perform onan author object.=cutsub author_tree { my $self = shift; my $authtree = $self->_author_tree; if( @_ ) { my @rv; for my $name (@_) { push @rv, $authtree->{$name} || ''; } return @rv == 1 ? $rv[0] : @rv; } else { return $authtree; }}=pod=head2 $conf = $cb->configure_object;Returns a copy of the C<CPANPLUS::Configure> object.See L<CPANPLUS::Configure> for operations you can perform on aconfigure object.=cutsub configure_object { return shift->_conf() };=head2 $su = $cb->selfupdate_object;Returns a copy of the C<CPANPLUS::Selfupdate> object.See the L<CPANPLUS::Selfupdate> manpage for the operationsyou can perform on the selfupdate object.=cutsub selfupdate_object { return shift->_selfupdate() };=pod=head2 @mods = $cb->search( type => TYPE, allow => AREF, [data => AREF, verbose => BOOL] )C<search> enables you to search for either module or author objects,based on their data. The C<type> you can specify is any of theaccessors specified in C<CPANPLUS::Module::Author> orC<CPANPLUS::Module>. C<search> will determine by the C<type> youspecified whether to search by author object or module object.You have to specify an array reference of regular expressions orstrings to match against. The rules used for this array ref are thesame as in C<Params::Check>, so read that manpage for details.The search is an C<or> search, meaning that if C<any> of the criteriamatch, the search is considered to be successful.You can specify the result of a previous search as C<data> to limitthe new search to these module or author objects, rather than theentire module or author tree. This is how you do C<and> searches.Returns a list of module or author objects on success and falseon failure.See L<CPANPLUS::Module> for the operations you can perform on amodule object.See L<CPANPLUS::Module::Author> for the operations you can perform onan author object.=cutsub search { my $self = shift; my $conf = $self->configure_object; my %hash = @_; my ($type); my $args = do { local $Params::Check::NO_DUPLICATES = 0; local $Params::Check::ALLOW_UNKNOWN = 1; my $tmpl = { type => { required => 1, allow => [CPANPLUS::Module->accessors(), CPANPLUS::Module::Author->accessors()], store => \$type }, allow => { required => 1, default => [ ], strict_type => 1 }, }; check( $tmpl, \%hash ) } or return; ### figure out whether it was an author or a module search ### when ambiguous, it'll be an author search. my $aref; if( grep { $type eq $_ } CPANPLUS::Module::Author->accessors() ) { $aref = $self->_search_author_tree( %$args ); } else { $aref = $self->_search_module_tree( %$args ); } return @$aref if $aref; return;}=pod=head2 $backend_rv = $cb->fetch( modules => \@mods )Fetches a list of modules. C<@mods> can be a list of distributionnames, module names or module objects--basically anything thatL<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=head2 $backend_rv = $cb->extract( modules => \@mods )Extracts a list of modules. C<@mods> can be a list of distributionnames, module names or module objects--basically anything thatL<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=head2 $backend_rv = $cb->install( modules => \@mods )Installs a list of modules. C<@mods> can be a list of distributionnames, module names or module objects--basically anything thatL<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=head2 $backend_rv = $cb->readme( modules => \@mods )Fetches the readme for a list of modules. C<@mods> can be a list ofdistribution names, module names or module objects--basicallyanything that L<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=head2 $backend_rv = $cb->files( modules => \@mods )Returns a list of files used by these modules if they are installed.C<@mods> can be a list of distribution names, module names or moduleobjects--basically anything that L<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=head2 $backend_rv = $cb->distributions( modules => \@mods )Returns a list of module objects representing all releases for thismodule on success.C<@mods> can be a list of distribution names, module names or moduleobjects, basically anything that L<parse_module> can understand.See the equivalent method in C<CPANPLUS::Module> for details onother options you can pass.Since this is a multi-module method call, the return value isimplemented as a C<CPANPLUS::Backend::RV> object. Please consultthat module's documentation on how to interpret the return value.=cut### XXX add direcotry_tree, packlist etc? or maybe remove files? ###for my $func (qw[fetch extract install readme files distributions]) { no strict 'refs'; *$func = sub { my $self = shift; my $conf = $self->configure_object; my %hash = @_; local $Params::Check::NO_DUPLICATES = 1; local $Params::Check::ALLOW_UNKNOWN = 1; my ($mods); my $tmpl = { modules => { default => [], strict_type => 1, required => 1, store => \$mods }, }; my $args = check( $tmpl, \%hash ) or return; ### make them all into module objects ### my %mods = map {$_ => $self->parse_module(module => $_) || ''} @$mods; my $flag; my $href; while( my($name,$obj) = each %mods ) { $href->{$name} = IS_MODOBJ->( mod => $obj ) ? $obj->$func( %$args ) : undef; $flag++ unless $href->{$name}; } return CPANPLUS::Backend::RV->new( function => $func, ok => !$flag, rv => $href, args => \%hash, ); }}=pod=head2 $mod_obj = $cb->parse_module( module => $modname|$distname|$modobj|URI )C<parse_module> tries to find a C<CPANPLUS::Module> object thatmatches your query. Here's a list of examples you could give toC<parse_module>;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -