📄 selfupdate.pm
字号:
for my $aref ( values %list ) { $aref = [ $latest ? grep { !$_->is_uptodate } @$aref : grep { !$_->is_installed_version_sufficient } @$aref ]; } return %list; } =head2 $bool = $self->selfupdate( update => "core|dependencies|enabled_features|features|all", [latest => BOOL, force => BOOL] )Selfupdate CPANPLUS. You can update either the core (CPANPLUS itself),the core dependencies, all features you have currently turned on, orall features available, or everything.The C<latest> option determines whether it should update to the latestversion on CPAN, or if the minimal required version for CPANPLUS isgood enough.Returns true on success, false on error.=cut sub selfupdate { my $self = shift; my $cb = $self->(); my $conf = $cb->configure_object; my %hash = @_; my $force; my $tmpl = { force => { default => $conf->get_conf('force'), store => \$force }, }; { local $Params::Check::ALLOW_UNKNOWN = 1; check( $tmpl, \%hash ) or return; } my %list = $self->list_modules_to_update( %hash ) or return; ### just the modules please my @mods = map { @$_ } values %list; my $flag; for my $mod ( @mods ) { unless( $mod->install( force => $force ) ) { $flag++; error(loc("Failed to update module '%1'", $mod->name)); } } return if $flag; return 1; } }=head2 @features = $self->list_featuresReturns a list of features that are supported by CPANPLUS.=cutsub list_features { my $self = shift; return keys %{ $self->_get_config->{'features'} };}=head2 @features = $self->list_enabled_featuresReturns a list of features that are enabled in your currentCPANPLUS installation.=cutsub list_enabled_features { my $self = shift; my $cb = $self->(); my @enabled; for my $feat ( $self->list_features ) { my $ref = $self->_get_config->{'features'}->{$feat}->[1]; push @enabled, $feat if $ref->($cb); } return @enabled;}=head2 @mods = $self->modules_for_feature( FEATURE [,AS_HASH] )Returns a list of C<CPANPLUS::Selfupdate::Module> objects which represent the modules required to support this feature.For a list of features, call the C<list_features> method.If the C<AS_HASH> argument is provided, no module objects arereturned, but a hashref where the keys are names of the modules,and values are their minimum versions.=cutsub modules_for_feature { my $self = shift; my $feature = shift or return; my $as_hash = shift || 0; my $cb = $self->(); unless( exists $self->_get_config->{'features'}->{$feature} ) { error(loc("Unknown feature '%1'", $feature)); return; } my $ref = $self->_get_config->{'features'}->{$feature}->[0]; ### it's either a list of modules/versions or a subroutine that ### returns a list of modules/versions my $href = UNIVERSAL::isa( $ref, 'HASH' ) ? $ref : $ref->( $cb ); return unless $href; # nothing needed for the feature? return $href if $as_hash; return $self->_hashref_to_module( $href );}=head2 @mods = $self->list_core_dependencies( [AS_HASH] )Returns a list of C<CPANPLUS::Selfupdate::Module> objects which represent the modules that comprise the core dependencies of CPANPLUS.If the C<AS_HASH> argument is provided, no module objects arereturned, but a hashref where the keys are names of the modules,and values are their minimum versions.=cutsub list_core_dependencies { my $self = shift; my $as_hash = shift || 0; my $cb = $self->(); my $href = $self->_get_config->{'dependencies'}; return $href if $as_hash; return $self->_hashref_to_module( $href );}=head2 @mods = $self->list_core_modules( [AS_HASH] )Returns a list of C<CPANPLUS::Selfupdate::Module> objects which represent the modules that comprise the core of CPANPLUS.If the C<AS_HASH> argument is provided, no module objects arereturned, but a hashref where the keys are names of the modules,and values are their minimum versions.=cutsub list_core_modules { my $self = shift; my $as_hash = shift || 0; my $cb = $self->(); my $href = $self->_get_config->{'core'}; return $href if $as_hash; return $self->_hashref_to_module( $href );}sub _hashref_to_module { my $self = shift; my $cb = $self->(); my $href = shift or return; return map { CPANPLUS::Selfupdate::Module->new( $cb->module_tree($_) => $href->{$_} ) } keys %$href;} =head1 CPANPLUS::Selfupdate::ModuleC<CPANPLUS::Selfupdate::Module> extends C<CPANPLUS::Module> objectsby providing accessors to aid in selfupdating CPANPLUS.These objects are returned by all methods of C<CPANPLUS::Selfupdate>that return module objects.=cut{ package CPANPLUS::Selfupdate::Module; use base 'CPANPLUS::Module'; ### stores module name -> cpanplus required version ### XXX only can deal with 1 pair! my %Cache = (); my $Acc = 'version_required'; sub new { my $class = shift; my $mod = shift or return; my $ver = shift; return unless defined $ver; my $obj = $mod->clone; # clone the module object bless $obj, $class; # rebless it to our class $obj->$Acc( $ver ); return $obj; }=head2 $version = $mod->version_requiredReturns the version of this module required for CPANPLUS.=cut sub version_required { my $self = shift; $Cache{ $self->name } = shift() if @_; return $Cache{ $self->name }; } =head2 $bool = $mod->is_installed_version_sufficientReturns true if the installed version of this module is sufficientfor CPANPLUS, or false if it is not.=cut sub is_installed_version_sufficient { my $self = shift; return $self->is_uptodate( version => $self->$Acc ); }} 1;=pod=head1 BUG REPORTSPlease report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>.=head1 AUTHORThis module by Jos Boumans E<lt>kane@cpan.orgE<gt>.=head1 COPYRIGHTThe CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved.This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.=cut# Local variables:# c-indentation-style: bsd# c-basic-offset: 4# indent-tabs-mode: nil# End:# vim: expandtab shiftwidth=4:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -