« blib/lib/CPANPLUS/Dist/Autobundle.pm
↑ Summary
blib/lib/CPANPLUS/Shell/Default/Plugins/Source.pm »
| 1 | package CPANPLUS::Configure; | ||||||||||||||||||||||||||||
| 2 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 20 | ▶ | use CPANPLUS::Internals::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use CPANPLUS::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use CPANPLUS::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use Log::Message; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 20 | ▶ | use Module::Load qw[load]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 20 | ▶ | use Params::Check qw[check]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 20 | ▶ | use File::Basename qw[dirname]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 20 | ▶ | use Module::Loaded (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 20 | ▶ | use vars qw[$AUTOLOAD $VERSION $MIN_CONFIG_VERSION]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 20 | ▶ | use base qw[CPANPLUS::Internals::Utils]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 20 | local $Params::Check::VERBOSE = 1; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | ### require, avoid circular use ### | ||||||||||||||||||||||||||||
| 22 | 20 | require CPANPLUS::Internals; | |||||||||||||||||||||||||||
| 23 | 20 | $VERSION = "0.9914"; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ### can't use O::A as we're using our own AUTOLOAD to get to | ||||||||||||||||||||||||||||
| 26 | ### the config options. | ||||||||||||||||||||||||||||
| 27 | 20 | for my $meth ( qw[conf _lib _perl5lib]) { | |||||||||||||||||||||||||||
| 28 | 20 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | *$meth = sub { | ||||||||||||||||||||||||||||
| 31 | 3970 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 3970 | ▶ | $self->{'_'.$meth} = $_[0] if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 3970 | return $self->{'_'.$meth}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 60 | } | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =pod | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 NAME | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | CPANPLUS::Configure - configuration for CPANPLUS | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | $conf = CPANPLUS::Configure->new( ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | $bool = $conf->can_save; | ||||||||||||||||||||||||||||
| 49 | $bool = $conf->save( $where ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | @opts = $conf->options( $type ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | $make = $conf->get_program('make'); | ||||||||||||||||||||||||||||
| 54 | $verbose = $conf->set_conf( verbose => 1 ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | This module deals with all the configuration issues for CPANPLUS. | ||||||||||||||||||||||||||||
| 59 | Users can use objects created by this module to alter the behaviour | ||||||||||||||||||||||||||||
| 60 | of CPANPLUS. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Please refer to the C<CPANPLUS::Backend> documentation on how to | ||||||||||||||||||||||||||||
| 63 | obtain a C<CPANPLUS::Configure> object. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 METHODS | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head2 $Configure = CPANPLUS::Configure->new( load_configs => BOOL ) | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | This method returns a new object. Normal users will never need to | ||||||||||||||||||||||||||||
| 70 | invoke the C<new> method, but instead retrieve the desired object via | ||||||||||||||||||||||||||||
| 71 | a method call on a C<CPANPLUS::Backend> object. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =over 4 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item load_configs | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Controls whether or not additional user configurations are to be loaded | ||||||||||||||||||||||||||||
| 78 | or not. Defaults to C<true>. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =back | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ### store the CPANPLUS::Config object in a closure, so we only | ||||||||||||||||||||||||||||
| 85 | ### initialize it once.. otherwise, on a 2nd ->new, settings | ||||||||||||||||||||||||||||
| 86 | ### from configs on top of this one will be reset | ||||||||||||||||||||||||||||
| 87 | 20 | { my $Config; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub new { | ||||||||||||||||||||||||||||
| 90 | 17 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 17 | my %hash = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ### XXX pass on options to ->init() like rescan? | ||||||||||||||||||||||||||||
| 94 | 17 | my ($load); | |||||||||||||||||||||||||||
| 95 | 17 | my $tmpl = { | |||||||||||||||||||||||||||
| 96 | load_configs => { default => 1, store => \$load }, | ||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 17 | ▶ | check( $tmpl, \%hash ) or ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | warn(Params::Check->last_error), return | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 17 | ▶ | $Config ||= CPANPLUS::Config->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$Config ||= "CPANPLUS::Config"->new
MC/DC0%0/2
$Config ||= "CPANPLUS::Config"->new
$Config
"CPANPLUS::Config"->new
Truth table33%1/3
A ||= B
A= $ConfigB= "CPANPLUS::Config"->new
| |||||||||||||||||||||||||||||
| 104 | 17 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 105 | 17 | $self->conf( $Config ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | ### you want us to load other configs? | ||||||||||||||||||||||||||||
| 108 | ### these can override things in the default config | ||||||||||||||||||||||||||||
| 109 | 17 | ▶ | $self->init if $load; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | ### after processing the config files, check what | ||||||||||||||||||||||||||||
| 112 | ### @INC and PERL5LIB are set to. | ||||||||||||||||||||||||||||
| 113 | 17 | $self->_lib( \@INC ); | |||||||||||||||||||||||||||
| 114 | 17 | $self->_perl5lib( $ENV{'PERL5LIB'} ); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 17 | return $self; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head2 $bool = $Configure->init( [rescan => BOOL]) | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Initialize the configure with other config files than just | ||||||||||||||||||||||||||||
| 123 | the default 'CPANPLUS::Config'. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Called from C<new()> to load user/system configurations | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | If the C<rescan> option is provided, your disk will be | ||||||||||||||||||||||||||||
| 128 | examined again to see if there are new config files that | ||||||||||||||||||||||||||||
| 129 | could be read. Defaults to C<false>. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Returns true on success, false on failure. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | ### move the Module::Pluggable detection to runtime, rather | ||||||||||||||||||||||||||||
| 136 | ### than compile time, so that a simple 'require CPANPLUS' | ||||||||||||||||||||||||||||
| 137 | ### doesn't start running over your filesystem for no good | ||||||||||||||||||||||||||||
| 138 | ### reason. Make sure we only do the M::P call once though. | ||||||||||||||||||||||||||||
| 139 | ### we use $loaded to mark it | ||||||||||||||||||||||||||||
| 140 | 20 | { my $loaded; | |||||||||||||||||||||||||||
| 141 | 20 | my $warned; | |||||||||||||||||||||||||||
| 142 | sub init { | ||||||||||||||||||||||||||||
| 143 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=14 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 4 | my $obj = $self->conf; | |||||||||||||||||||||||||||
| 145 | 4 | my %hash = @_; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 4 | my ($rescan); | |||||||||||||||||||||||||||
| 148 | 4 | my $tmpl = { | |||||||||||||||||||||||||||
| 149 | rescan => { default => 0, store => \$rescan }, | ||||||||||||||||||||||||||||
| 150 | }; | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 4 | ▶ | check( $tmpl, \%hash ) or ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | warn(Params::Check->last_error), return | ||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | ### if the base dir is changed, we have to rescan it | ||||||||||||||||||||||||||||
| 157 | ### for any CPANPLUS::Config::* files as well, so keep | ||||||||||||||||||||||||||||
| 158 | ### track of it | ||||||||||||||||||||||||||||
| 159 | 4 | my $cur_base = $self->get_conf('base'); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | ### warn if we find an old style config specified | ||||||||||||||||||||||||||||
| 162 | ### via environment variables | ||||||||||||||||||||||||||||
| 163 | 4 | { my $env = ENV_CPANPLUS_CONFIG; | |||||||||||||||||||||||||||
| 164 | 4 | ▶ | if( $ENV{$env} and not $warned ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{$env} and not $warned
MC/DC50%1/2
$ENV{$env} and not $warned
$ENV{$env}
not $warned
Truth table66%2/3
A and not(B)
A= $ENV{$env}B= not $warned
| |||||||||||||||||||||||||||||
| 165 | 1 | $warned++; | |||||||||||||||||||||||||||
| 166 | 1 | error(loc("Specifying a config file in your environment " . | |||||||||||||||||||||||||||
| 167 | "using %1 is obsolete.\nPlease follow the ". | ||||||||||||||||||||||||||||
| 168 | "directions outlined in %2 or use the '%3' command\n". | ||||||||||||||||||||||||||||
| 169 | "in the default shell to use custom config files.", | ||||||||||||||||||||||||||||
| 170 | $env, "CPANPLUS::Configure->save", 's save')); | ||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | { ### make sure that the homedir is included now | ||||||||||||||||||||||||||||
| 175 | 4 | local @INC = ( LIB_DIR->($cur_base), @INC ); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | ### only set it up once | ||||||||||||||||||||||||||||
| 178 | 4 | ▶ | if( !$loaded++ or $rescan ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $loaded++ or $rescan
MC/DC100%2/2
not $loaded++ or $rescan
not $loaded++
$rescan
Truth table100%3/3
not(A) or B
A= not $loaded++B= $rescan
| |||||||||||||||||||||||||||||
| 179 | ### find plugins & extra configs | ||||||||||||||||||||||||||||
| 180 | ### check $home/.cpanplus/lib as well | ||||||||||||||||||||||||||||
| 181 | 3 | require Module::Pluggable; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 3 | Module::Pluggable->import( | |||||||||||||||||||||||||||
| 184 | search_path => ['CPANPLUS::Config'], | ||||||||||||||||||||||||||||
| 185 | search_dirs => [ LIB_DIR->($cur_base) ], | ||||||||||||||||||||||||||||
| 186 | except => qr/::SUPER$/, | ||||||||||||||||||||||||||||
| 187 | sub_name => 'configs' | ||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | ### do system config, user config, rest.. in that order | ||||||||||||||||||||||||||||
| 193 | ### apparently, on a 2nd invocation of -->configs, a | ||||||||||||||||||||||||||||
| 194 | ### ::ISA::CACHE package can appear.. that's bad... | ||||||||||||||||||||||||||||
| 195 | 6 | my %confs = map { $_ => $_ } | |||||||||||||||||||||||||||
| 196 | 4 | grep { $_ !~ /::ISA::/ } __PACKAGE__->configs; | |||||||||||||||||||||||||||
| 197 | 8 | my @confs = grep { defined } | |||||||||||||||||||||||||||
| 198 | 4 | map { delete $confs{$_} } CONFIG_SYSTEM, CONFIG_USER; | |||||||||||||||||||||||||||
| 199 | 4 | push @confs, sort keys %confs; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 4 | for my $plugin ( @confs ) { | |||||||||||||||||||||||||||
| 202 | 6 | msg(loc("Found config '%1'", $plugin),0); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | ### if we already did this the /last/ time around don't | ||||||||||||||||||||||||||||
| 205 | ### run the setup again. | ||||||||||||||||||||||||||||
| 206 | 6 | ▶ | if( my $loc = Module::Loaded::is_loaded( $plugin ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 3 | msg(loc(" Already loaded '%1' (%2)", $plugin, $loc), 0); | |||||||||||||||||||||||||||
| 208 | 3 | next; | |||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||
| 210 | 3 | msg(loc(" Loading config '%1'", $plugin),0); | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 3 | ▶ | if( eval { load $plugin; 1 } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 3 | msg(loc(" Loaded '%1' (%2)", | |||||||||||||||||||||||||||
| 214 | $plugin, Module::Loaded::is_loaded( $plugin ) ), 0); | ||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||
| 216 | 0 | error(loc(" Error loading '%1': %2", $plugin, $@)); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 3 | ▶ | if( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | error(loc("Could not load '%1': %2", $plugin, $@)); | |||||||||||||||||||||||||||
| 222 | 0 | next; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 3 | my $sub = $plugin->can('setup'); | |||||||||||||||||||||||||||
| 226 | 3 | ▶ | $sub->( $self ) if $sub; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | ### did one of the plugins change the base dir? then we should | ||||||||||||||||||||||||||||
| 231 | ### scan the dirs again | ||||||||||||||||||||||||||||
| 232 | 4 | ▶ | if( $cur_base ne $self->get_conf('base') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 0 | msg(loc("Base dir changed from '%1' to '%2', rescanning", | |||||||||||||||||||||||||||
| 234 | $cur_base, $self->get_conf('base')), 0); | ||||||||||||||||||||||||||||
| 235 | 0 | $self->init( @_, rescan => 1 ); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | ### clean up the paths once more, just in case | ||||||||||||||||||||||||||||
| 239 | 4 | $obj->_clean_up_paths; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | ### XXX in case the 'lib' param got changed, we need to | ||||||||||||||||||||||||||||
| 242 | ### add that now, or it's not propagating ;( | ||||||||||||||||||||||||||||
| 243 | 4 | { my $lib = $self->get_conf('lib'); | |||||||||||||||||||||||||||
| 244 | 4 | my %inc = map { $_ => $_ } @INC; | |||||||||||||||||||||||||||
| 245 | 4 | for my $l ( @$lib ) { | |||||||||||||||||||||||||||
| 246 | 0 | ▶ | push @INC, $l unless $inc{$l}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 4 | $self->_lib( \@INC ); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 4 | return 1; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | =pod | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head2 can_save( [$config_location] ) | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Check if we can save the configuration to the specified file. | ||||||||||||||||||||||||||||
| 259 | If no file is provided, defaults to your personal config. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | Returns true if the file can be saved, false otherwise. | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 20 | sub can_save { | |||||||||||||||||||||||||||
| 266 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
can_save: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 1 | ▶ | my $file = shift || CONFIG_USER_FILE->(); | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || sub {
package CPANPLUS::Internals::Constants;
'File::Spec'->catfile(sub {
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->(), split(/::/, 'CPANPLUS::Config::User', 0)) . '.pm';
}
->()
MC/DC0%0/2
shift() || sub {
package CPANPLUS::Internals::Constants;
'File::Spec'->catfile(sub {
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->(), split(/::/, 'CPANPLUS::Config::User', 0)) . '.pm';
}
->()
shift()
sub {
package CPANPLUS::Internals::Constants;
'File::Spec'->catfile(sub {
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->(), split(/::/, 'CPANPLUS::Config::User', 0)) . '.pm';
}
->()
Truth table33%1/3
A || B
A= shift()B= sub {
package CPANPLUS::Internals::Constants;
'File::Spec'->catfile(sub {
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->(), split(/::/, 'CPANPLUS::Config::User', 0)) . '.pm';
}
->()
| |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 1 | ▶ | return 1 unless -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | chmod 0644, $file; | |||||||||||||||||||||||||||
| 272 | 0 | return (-w $file); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | =pod | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =head2 $file = $conf->save( [$package_name] ) | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | Saves the configuration to the package name you provided. | ||||||||||||||||||||||||||||
| 280 | If this package is not C<CPANPLUS::Config::System>, it will | ||||||||||||||||||||||||||||
| 281 | be saved in your C<.cpanplus> directory, otherwise it will | ||||||||||||||||||||||||||||
| 282 | be attempted to be saved in the system wide directory. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | If no argument is provided, it will default to your personal | ||||||||||||||||||||||||||||
| 285 | config. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | Returns the full path to the file if the config was saved, | ||||||||||||||||||||||||||||
| 288 | false otherwise. | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | sub _config_pm_to_file { | ||||||||||||||||||||||||||||
| 293 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_config_pm_to_file: called CC=6 SCAR=21.0
| |||||||||||||||||||||||||||||
| 294 | 1 | ▶ | my $pm = shift or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 1 | ▶ | my $dir = shift || CONFIG_USER_LIB_DIR->(); | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || sub {
package CPANPLUS::Internals::Constants;
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->()
MC/DC0%0/2
shift() || sub {
package CPANPLUS::Internals::Constants;
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->()
shift()
sub {
package CPANPLUS::Internals::Constants;
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->()
Truth table33%1/3
A || B
A= shift()B= sub {
package CPANPLUS::Internals::Constants;
require CPANPLUS::Internals::Utils;
sub {
return @_ ? 'File::Spec'->catdir(@_, 'lib') : 'lib';
}
->('CPANPLUS::Internals::Utils'->_home_dir, '.cpanplus');
}
->()
| |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | ### only 3 types of files know: home, system and 'other' | ||||||||||||||||||||||||||||
| 298 | ### so figure out where to save them based on their type | ||||||||||||||||||||||||||||
| 299 | 1 | my $file; | |||||||||||||||||||||||||||
| 300 | 1 | ▶ | if( $pm eq CONFIG_USER ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 301 | 0 | $file = CONFIG_USER_FILE->(); | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | } elsif ( $pm eq CONFIG_SYSTEM ) { | ||||||||||||||||||||||||||||
| 304 | 0 | $file = CONFIG_SYSTEM_FILE->(); | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | ### third party file | ||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||
| 308 | 1 | my $cfg_pkg = CONFIG . '::'; | |||||||||||||||||||||||||||
| 309 | 1 | ▶ | unless( $pm =~ /^$cfg_pkg/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | error(loc( | |||||||||||||||||||||||||||
| 311 | "WARNING: Your config package '%1' is not in the '%2' ". | ||||||||||||||||||||||||||||
| 312 | "namespace and will not be automatically detected by %3", | ||||||||||||||||||||||||||||
| 313 | $pm, $cfg_pkg, 'CPANPLUS' | ||||||||||||||||||||||||||||
| 314 | )); | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 1 | $file = File::Spec->catfile( | |||||||||||||||||||||||||||
| 318 | $dir, | ||||||||||||||||||||||||||||
| 319 | split( '::', $pm ) | ||||||||||||||||||||||||||||
| 320 | ) . '.pm'; | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 1 | return $file; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | sub save { | ||||||||||||||||||||||||||||
| 328 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=11 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||
| 329 | 1 | ▶ | my $pm = shift || CONFIG_USER; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'CPANPLUS::Config::User'
MC/DC0%0/1
shift() || 'CPANPLUS::Config::User'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 330 | 1 | ▶ | my $savedir = shift || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 1 | ▶ | my $file = $self->_config_pm_to_file( $pm, $savedir ) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 1 | my $dir = dirname( $file ); | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 1 | ▶ | unless( -d $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 1 | ▶ | $self->_mkdir( dir => $dir ) or ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | error(loc("Can not create directory '%1' to save config to",$dir)), | ||||||||||||||||||||||||||||
| 338 | return | ||||||||||||||||||||||||||||
| 339 | ) | ||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 1 | ▶ | return unless $self->can_save($file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | ### find only accessors that are not private | ||||||||||||||||||||||||||||
| 344 | 1 | my @acc = sort grep { $_ !~ /^_/ } $self->conf->ls_accessors; | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | ### for dumping the values | ||||||||||||||||||||||||||||
| 347 | 20 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 1 | my @lines; | |||||||||||||||||||||||||||
| 350 | 1 | for my $acc ( @acc ) { | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 2 | push @lines, "### $acc section", $/; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 2 | for my $key ( $self->conf->$acc->ls_accessors ) { | |||||||||||||||||||||||||||
| 355 | 43 | my $val = Dumper( $self->conf->$acc->$key ); | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 43 | $val =~ s/\$VAR1\s+=\s+//; | |||||||||||||||||||||||||||
| 358 | 43 | $val =~ s/;\n//; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 43 | push @lines, '$'. "conf->set_${acc}( $key => $val );", $/; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 2 | push @lines, $/,$/; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 1 | my $str = join '', map { " $_" } @lines; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | ### use a variable to make sure the pod parser doesn't snag it | ||||||||||||||||||||||||||||
| 369 | 1 | my $is = '='; | |||||||||||||||||||||||||||
| 370 | 1 | my $time = gmtime; | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 1 | my $msg = <<_END_OF_CONFIG_; | |||||||||||||||||||||||||||
| 374 | ############################################### | ||||||||||||||||||||||||||||
| 375 | ### | ||||||||||||||||||||||||||||
| 376 | ### Configuration structure for $pm | ||||||||||||||||||||||||||||
| 377 | ### | ||||||||||||||||||||||||||||
| 378 | ############################################### | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | #last changed: $time GMT | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | ### minimal pod, so you can find it with perldoc -l, etc | ||||||||||||||||||||||||||||
| 383 | ${is}pod | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | ${is}head1 NAME | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | $pm | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | ${is}head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | This is a CPANPLUS configuration file. Editing this | ||||||||||||||||||||||||||||
| 392 | config changes the way CPANPLUS will behave | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | ${is}cut | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | package $pm; | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | use strict; | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | sub setup { | ||||||||||||||||||||||||||||
| 401 | my \$conf = shift; | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | $str | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | return 1; | ||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 1; | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | _END_OF_CONFIG_ | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 1 | ▶ | $self->_move( file => $file, to => "$file~" ) if -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 1 | my $fh = new FileHandle; | |||||||||||||||||||||||||||
| 415 | 1 | ▶ | $fh->open(">$file") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | or (error(loc("Could not open '%1' for writing: %2", $file, $!)), | ||||||||||||||||||||||||||||
| 417 | return ); | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 1 | $fh->print($msg); | |||||||||||||||||||||||||||
| 420 | 1 | $fh->close; | |||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 1 | return $file; | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =pod | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head2 options( type => TYPE ) | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | Returns a list of all valid config options given a specific type | ||||||||||||||||||||||||||||
| 430 | (like for example C<conf> of C<program>) or false if the type does | ||||||||||||||||||||||||||||
| 431 | not exist | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | sub options { | ||||||||||||||||||||||||||||
| 436 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
options: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 437 | 6 | my $conf = $self->conf; | |||||||||||||||||||||||||||
| 438 | 6 | my %hash = @_; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 6 | my $type; | |||||||||||||||||||||||||||
| 441 | 6 | my $tmpl = { | |||||||||||||||||||||||||||
| 442 | type => { required => 1, default => '', | ||||||||||||||||||||||||||||
| 443 | strict_type => 1, store => \$type }, | ||||||||||||||||||||||||||||
| 444 | }; | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 6 | ▶ | check($tmpl, \%hash) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 6 | my %seen; | |||||||||||||||||||||||||||
| 449 | 63 | return sort grep { !$seen{$_}++ } | |||||||||||||||||||||||||||
| 450 | 6 | ▶ | map { $_->$type->ls_accessors if $_->can($type) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | $self->conf; | ||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | =pod | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | Accessors that start with a C<_> are marked private -- regular users | ||||||||||||||||||||||||||||
| 459 | should never need to use these. | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | See the C<CPANPLUS::Config> documentation for what items can be | ||||||||||||||||||||||||||||
| 462 | set and retrieved. | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | =head2 get_SOMETHING( ITEM, [ITEM, ITEM, ... ] ); | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | The C<get_*> style accessors merely retrieves one or more desired | ||||||||||||||||||||||||||||
| 467 | config options. | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | =head2 set_SOMETHING( ITEM => VAL, [ITEM => VAL, ITEM => VAL, ... ] ); | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | The C<set_*> style accessors set the current value for one | ||||||||||||||||||||||||||||
| 472 | or more config options and will return true upon success, false on | ||||||||||||||||||||||||||||
| 473 | failure. | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =head2 add_SOMETHING( ITEM => VAL, [ITEM => VAL, ITEM => VAL, ... ] ); | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | The C<add_*> style accessor adds a new key to a config key. | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | Currently, the following accessors exist: | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | =over 4 | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | =item set|get_conf | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | Simple configuration directives like verbosity and favourite shell. | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | =item set|get_program | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | Location of helper programs. | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | =item _set|_get_build | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | Locations of where to put what files for CPANPLUS. | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | =item _set|_get_source | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | Locations and names of source files locally. | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | =item _set|_get_mirror | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | Locations and names of source files remotely. | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | =item _set|_get_fetch | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | Special settings pertaining to the fetching of files. | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | =back | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | =cut | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | sub AUTOLOAD { | ||||||||||||||||||||||||||||
| 512 | 3842 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=17 SCAR=30.3
| |||||||||||||||||||||||||||||
| 513 | 3842 | my $conf = $self->conf; | |||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 3842 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||
| 516 | 3842 | $name =~ s/.+:://; | |||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 3842 | my ($private, $action, $field) = | |||||||||||||||||||||||||||
| 519 | $name =~ m/^(_)?((?:[gs]et|add))_([a-z]+)$/; | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 3842 | my $type = ''; | |||||||||||||||||||||||||||
| 522 | 3842 | ▶ | $type .= '_' if $private; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | 3842 | ▶ | $type .= $field if $field; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 3842 | my $type_code = $conf->can($type); | |||||||||||||||||||||||||||
| 526 | 3842 | ▶ | unless ( $type_code ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 527 | 1 | error( loc("Invalid method type: '%1'", $name) ); | |||||||||||||||||||||||||||
| 528 | 1 | return; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | 3841 | my $type_obj = $type_code->(); | |||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 3841 | ▶ | unless( scalar @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 533 | 0 | error( loc("No arguments provided!") ); | |||||||||||||||||||||||||||
| 534 | 0 | return; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | ### retrieve a current value for an existing key ### | ||||||||||||||||||||||||||||
| 538 | 3841 | ▶ | if( $action eq 'get' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 539 | 3501 | for my $key (@_) { | |||||||||||||||||||||||||||
| 540 | 3501 | my @list = (); | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | ### get it from the user config first | ||||||||||||||||||||||||||||
| 543 | 3501 | ▶ | if( my $code = $type_obj->can($key) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 544 | 3500 | push @list, $code->(); | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | ### XXX EU::AI compatibility hack to provide lookups like in | ||||||||||||||||||||||||||||
| 547 | ### cpanplus 0.04x; we renamed ->_get_build('base') to | ||||||||||||||||||||||||||||
| 548 | ### ->get_conf('base') | ||||||||||||||||||||||||||||
| 549 | ▶ | } elsif ( $type eq '_build' and $key eq 'base' ) { | |||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "_build" and $key eq "base"
MC/DC0%0/2
$type eq "_build" and $key eq "base"
$type eq "_build"
$key eq "base"
Truth table33%1/3
A and B
A= $type eq "_build"B= $key eq "base"
| |||||||||||||||||||||||||||||
| 550 | 1 | return $self->get_conf($key); | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | } else { | ||||||||||||||||||||||||||||
| 553 | 0 | error( loc(q[No such key '%1' in field '%2'], $key, $type) ); | |||||||||||||||||||||||||||
| 554 | 0 | return; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 3500 | ▶ | return wantarray ? @list : $list[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | ### set an existing key to a new value ### | ||||||||||||||||||||||||||||
| 561 | } elsif ( $action eq 'set' ) { | ||||||||||||||||||||||||||||
| 562 | 334 | my %args = @_; | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 334 | ▶ | while( my($key,$val) = each %args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | 334 | ▶ | if( my $code = $type_obj->can($key) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 567 | 334 | $code->( $val ); | |||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | } else { | ||||||||||||||||||||||||||||
| 570 | 0 | error( loc(q[No such key '%1' in field '%2'], $key, $type) ); | |||||||||||||||||||||||||||
| 571 | 0 | return; | |||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 334 | return 1; | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | ### add a new key to the config ### | ||||||||||||||||||||||||||||
| 578 | } elsif ( $action eq 'add' ) { | ||||||||||||||||||||||||||||
| 579 | 6 | my %args = @_; | |||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 6 | ▶ | while( my($key,$val) = each %args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 6 | ▶ | if( $type_obj->can($key) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 584 | 0 | error( loc( q[Key '%1' already exists for field '%2'], | |||||||||||||||||||||||||||
| 585 | $key, $type)); | ||||||||||||||||||||||||||||
| 586 | 0 | return; | |||||||||||||||||||||||||||
| 587 | } else { | ||||||||||||||||||||||||||||
| 588 | 6 | $type_obj->mk_accessors( $key ); | |||||||||||||||||||||||||||
| 589 | 6 | $type_obj->$key( $val ); | |||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | 6 | return 1; | |||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | } else { | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | 0 | error( loc(q[Unknown action '%1'], $action) ); | |||||||||||||||||||||||||||
| 597 | 0 | return; | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 3 | ▶ | sub DESTROY { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 20 | 1; | |||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | =pod | ||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||
| 607 | =head1 BUG REPORTS | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | Please report bugs or other issues to E<lt>bug-cpanplus@rt.cpan.org<gt>. | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | This module by Jos Boumans E<lt>kane@cpan.orgE<gt>. | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | The CPAN++ interface (of which this module is a part of) is copyright (c) | ||||||||||||||||||||||||||||
| 618 | 2001 - 2007, Jos Boumans E<lt>kane@cpan.orgE<gt>. All rights reserved. | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | This library is free software; you may redistribute and/or modify it | ||||||||||||||||||||||||||||
| 621 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | L<CPANPLUS::Backend>, L<CPANPLUS::Configure::Setup>, L<CPANPLUS::Config> | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | =cut | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | # Local variables: | ||||||||||||||||||||||||||||
| 630 | # c-indentation-style: bsd | ||||||||||||||||||||||||||||
| 631 | # c-basic-offset: 4 | ||||||||||||||||||||||||||||
| 632 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||
| 633 | # End: | ||||||||||||||||||||||||||||
| 634 | # vim: expandtab shiftwidth=4: | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||