Method returns a configuration value if defined, or the default
value that was passed in, otherwise.
The main purpose of this method is to allow the empty string to
be a valid configuration option, and to replace the following
construct:
$val = $repo->config('my.key') || $default_val
Signed-off-by: Dan Zwell <dzwell@zwell.net>
---
perl/Git.pm | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 6603762..7327300 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -549,6 +549,34 @@ sub config_bool {
};
}
+=item config_default ( VARIABLE, DEFAULT )
+
+Fetches a configuration option C<VARIABLE>, returning its
+value if it is defined (it is valid to return the empty string,
+if that is its value). Otherwise, C<DEFAULT>, a default
+value, is returned. This method may be a replacement for
+
+ my $value = $repo->config('my.key') || 'default val';
+
+in situations where the empty string is an acceptable return value.
+This method may also be called in a vector context, when expecting
+multivars.
+
+ my @value = $repo->config_default('my.multivar', \@default_vals);
+
+=cut
+
+sub config_default {
+ my ($self, $var, $default) = @_;
+ if (wantarray) {
+ my @value = $self->config($var);
+ return @value ? @value : @$default;
+ }
+ else {
+ my $value = $self->config($var);
+ return (defined $value) ? $value : $default;
+ }
+}
=item ident ( TYPE | IDENTSTR )
--
1.5.3.5.565.gf0b83-dirty
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Tarkan Erimer | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Amit K. Arora | [RFC] Heads up on sys_fallocate() |
| Chuck Ebbert | Why do so many machines need "noapic"? |
git: | |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| David Miller | [GIT]: Networking |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| Natalie Protasevich | [BUG] New Kernel Bugs |
