📄 module.pm
字号:
package CPANPLUS::Module;use strict;use vars qw[@ISA];use CPANPLUS::Dist;use CPANPLUS::Error;use CPANPLUS::Module::Signature;use CPANPLUS::Module::Checksums;use CPANPLUS::Internals::Constants;use FileHandle;use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';use IPC::Cmd qw[can_run run];use File::Find qw[find];use Params::Check qw[check];use Module::Load::Conditional qw[can_load check_install];$Params::Check::VERBOSE = 1;@ISA = qw[ CPANPLUS::Module::Signature CPANPLUS::Module::Checksums];=pod=head1 NAMECPANPLUS::Module=head1 SYNOPSIS ### get a module object from the CPANPLUS::Backend object my $mod = $cb->module_tree('Some::Module'); ### accessors $mod->version; $mod->package; ### methods $mod->fetch; $mod->extract; $mod->install;=head1 DESCRIPTIONC<CPANPLUS::Module> creates objects from the information in thesource files. These can then be used to query and perform actionson, like fetching or installing.These objects should only be created internally. For C<fake> objects,there's the C<CPANPLUS::Module::Fake> class. To obtain a module objectconsult the C<CPANPLUS::Backend> documentation.=cutmy $tmpl = { module => { default => '', required => 1 }, # full module name version => { default => '0.0' }, # version number path => { default => '', required => 1 }, # extended path on the # cpan mirror, like # /author/id/K/KA/KANE comment => { default => ''}, # comment on module package => { default => '', required => 1 }, # package name, like # 'bar-baz-1.03.tgz' description => { default => '' }, # description of the # module dslip => { default => EMPTY_DSLIP }, # dslip information _id => { required => 1 }, # id of the Internals # parent object _status => { no_override => 1 }, # stores status object author => { default => '', required => 1, allow => IS_AUTHOBJ }, # module author mtime => { default => '' },};### some of these will be resolved by wrapper functions that### do Clever Things to find the actual value, so don't create### an autogenerated sub for that just here, take an alternate### name to allow for a wrapper{ my %rename = ( dslip => '_dslip' ); ### autogenerate accessors ### for my $key ( keys %$tmpl ) { no strict 'refs'; my $sub = $rename{$key} || $key; *{__PACKAGE__."::$sub"} = sub { $_[0]->{$key} = $_[1] if @_ > 1; return $_[0]->{$key}; } }}=pod=head1 CLASS METHODS=head2 accessors ()Returns a list of all accessor methods to the object=cut### *name is an alias, include it explicitlysub accessors { return ('name', keys %$tmpl) };=head1 ACCESSORSAn objects of this class has the following accessors:=over 4=item nameName of the module.=item moduleName of the module.=item versionVersion of the module. Defaults to '0.0' if none was provided.=item pathExtended path on the mirror.=item commentAny comment about the module -- largely unused.=item packageThe name of the package.=item descriptionDescription of the module -- only registered modules have this.=item dslipThe five character dslip string, that represents meta-data of themodule -- again, only registered modules have this.=cutsub dslip { my $self = shift; ### if this module has relevant dslip info, return it return $self->_dslip if $self->_dslip ne EMPTY_DSLIP; ### if not, look at other modules in the same package, ### see if *they* have any dslip info for my $mod ( $self->contains ) { return $mod->_dslip if $mod->_dslip ne EMPTY_DSLIP; } ### ok, really no dslip info found, return the default return EMPTY_DSLIP;}=pod=item statusThe C<CPANPLUS::Module::Status> object associated with this object.(see below).=item authorThe C<CPANPLUS::Module::Author> object associated with this object.=item parentThe C<CPANPLUS::Internals> object that spawned this module object.=back=cut### Alias ->name to ->module, for human beings.*name = *module;sub parent { my $self = shift; my $obj = CPANPLUS::Internals->_retrieve_id( $self->_id ); return $obj;}=head1 STATUS ACCESSORSC<CPANPLUS> caches a lot of results from method calls and saves datait collected along the road for later reuse.C<CPANPLUS> uses this internally, but it is also available for the enduser. You can get a status object by calling: $modobj->statusYou can then query the object as follows:=over 4=item installer_typeThe installer type used for this distribution. Will be one of'makemaker' or 'build'. This determines whether C<CPANPLUS::Dist::MM>or C<CPANPLUS::Dist::Build> will be used to build this distribution.=item dist_cpanThe dist object used to do the CPAN-side of the installation. Eithera C<CPANPLUS::Dist::MM> or C<CPANPLUS::Dist::Build> object.=item distThe custom dist object used to do the operating specific side of theinstallation, if you've chosen to use this. For example, if you'vechosen to install using the C<ports> format, this may be aC<CPANPLUS::Dist::Ports> object.Undefined if you didn't specify a separate format to install through.=item prereqsA hashref of prereqs this distribution was found to have. Will looksomething like this: { Carp => 0.01, strict => 0 }Might be undefined if the distribution didn't have any prerequisites.=item signatureFlag indicating, if a signature check was done, whether it was OK ornot.=item extractThe directory this distribution was extracted to.=item fetchThe location this distribution was fetched to.=item readmeThe text of this distributions README file.=item uninstallFlag indicating if an uninstall call was done successfully.=item createdFlag indicating if the C<create> call to your dist object was donesuccessfully.=item installedFlag indicating if the C<install> call to your dist object was donesuccessfully.=item checksumsThe location of this distributions CHECKSUMS file.=item checksum_okFlag indicating if the checksums check was done successfully.=item checksum_valueThe checksum value this distribution is expected to have=back=head1 METHODS=head2 $self = CPANPLUS::Module::new( OPTIONS )This method returns a C<CPANPLUS::Module> object. Normal usersshould never call this method directly, but instead use theC<CPANPLUS::Backend> to obtain module objects.This example illustrates a C<new()> call with all required arguments: CPANPLUS::Module->new( module => 'Foo', path => 'authors/id/A/AA/AAA', package => 'Foo-1.0.tgz', author => $author_object, _id => INTERNALS_OBJECT_ID, );Every accessor is also a valid option to pass to C<new>.Returns a module object on success and false on failure.=cutsub new { my($class, %hash) = @_; ### don't check the template for sanity ### -- we know it's good and saves a lot of performance local $Params::Check::SANITY_CHECK_TEMPLATE = 0; my $object = check( $tmpl, \%hash ) or return; bless $object, $class; return $object;}### only create status objects when they're actually asked forsub status { my $self = shift; return $self->_status if $self->_status; my $acc = Object::Accessor->new; $acc->mk_accessors( qw[ installer_type dist_cpan dist prereqs signature extract fetch readme uninstall created installed prepared checksums files checksum_ok checksum_value _fetch_from] ); $self->_status( $acc ); return $self->_status;}### flush the cache of this object ###sub _flush { my $self = shift; $self->status->mk_flush; return 1;}=head2 $mod->package_nameReturns the name of the package a module is in. For C<Acme::Bleach>that might be C<Acme-Bleach>.=head2 $mod->package_versionReturns the version of the package a module is in. For a modulein the package C<Acme-Bleach-1.1.tar.gz> this would be C<1.1>.=head2 $mod->package_extensionReturns the suffix added by the compression method of a package acertain module is in. For a module in C<Acme-Bleach-1.1.tar.gz>, thiswould be C<tar.gz>.=head2 $mod->package_is_perl_coreReturns a boolean indicating of the package a particular module is in,is actually a core perl distribution.=head2 $mod->module_is_supplied_with_perl_core( [version => $]] )Returns a boolean indicating whether C<ANY VERSION> of this modulewas supplied with the current running perl's core package.=head2 $mod->is_bundleReturns a boolean indicating if the module you are looking at, isactually a bundle. Bundles are identified as modules whose name startswith C<Bundle::>.=head2 $mod->is_third_partyReturns a boolean indicating whether the package is a known third-party module (i.e. it's not provided by the standard Perl distribution and is not available on the CPAN, but on a third party software provider).See L<Module::ThirdParty> for more details.=head2 $mod->third_party_informationReturns a reference to a hash with more information about a third-partymodule. See the documentation about C<module_information()> in L<Module::ThirdParty> for more details.=cut{ ### fetches the test reports for a certain module ### my %map = ( name => 0, version => 1, extension => 2, );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -