From: Simon McVittie <smcv@debian.org>
Date: Tue, 9 Dec 2014 20:02:03 +0000 (+0000)
Subject: Simplify libdirs: libdirs must be plural, libdir must be a single string
X-Git-Tag: 3.20150107~36
X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/b3e21b043670c946a081d33740cfc2a0eb552c34?hp=-c

Simplify libdirs: libdirs must be plural, libdir must be a single string

This makes the documentation read more sensibly, and matches how we
handle underlaydirs and underlaydir.
---

b3e21b043670c946a081d33740cfc2a0eb552c34
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 7c55764be..41baa6613 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -358,11 +358,20 @@ sub getsetup () {
 		safe => 0, # paranoia
 		rebuild => 0,
 	},
+	libdirs => {
+		type => "string",
+		default => [],
+		example => ["$ENV{HOME}/.local/share/ikiwiki"],
+		description => "extra library and plugin directories",
+		advanced => 1,
+		safe => 0, # directory
+		rebuild => 0,
+	},
 	libdir => {
 		type => "string",
 		default => "",
 		example => "$ENV{HOME}/.ikiwiki/",
-		description => "extra library and plugin directorys. Can be either a string (for backward compatibility) or a list of strings.",
+		description => "extra library and plugin directory (searched after libdirs)",
 		advanced => 1,
 		safe => 0, # directory
 		rebuild => 0,
@@ -560,17 +569,11 @@ sub getsetup () {
 }
 
 sub getlibdirs () {
-	my $libdirs;
-	if (! ref $config{libdir}) {
-		if (length $config{libdir}) {
-			$libdirs = [$config{libdir}];
-		} else {
-			$libdirs = [];
-		}
-	} else {
-		$libdirs = $config{libdir};
+	my @libdirs = @{$config{libdirs}};
+	if (length $config{libdir}) {
+		push @libdirs, $config{libdir};
 	}
-	return @{$libdirs};
+	return @libdirs;
 }
 
 sub defaultconfig () {
@@ -733,10 +736,8 @@ sub listplugins () {
 }
 
 sub loadplugins () {
-	if (defined $config{libdir} && length $config{libdir}) {
-		foreach my $dir (getlibdirs()) {
-			unshift @INC, possibly_foolish_untaint($dir);
-		}
+	foreach my $dir (getlibdirs()) {
+		unshift @INC, possibly_foolish_untaint($dir);
 	}
 
 	foreach my $plugin (@{$config{default_plugins}}, @{$config{add_plugins}}) {
@@ -770,7 +771,7 @@ sub loadplugin ($;$) {
 	return if ! $force && grep { $_ eq $plugin} @{$config{disable_plugins}};
 
 	foreach my $possiblytainteddir (getlibdirs(), "$installdir/lib/ikiwiki") {
-		my $dir = defined $possiblytainteddir ? possibly_foolish_untaint($possiblytainteddir) : undef;
+		my $dir = possibly_foolish_untaint($possiblytainteddir);
 		if (defined $dir && -x "$dir/plugins/$plugin") {
 			eval { require IkiWiki::Plugin::external };
 			if ($@) {
diff --git a/doc/plugins/install.mdwn b/doc/plugins/install.mdwn
index 8ae1c8bde..e810d8777 100644
--- a/doc/plugins/install.mdwn
+++ b/doc/plugins/install.mdwn
@@ -8,14 +8,14 @@ inside the perl search path. For example, if your perl looks in
 `/usr/local/lib/site_perl` for modules, you can locally install ikiwiki
 plugins to `/usr/local/lib/site_perl/IkiWiki/Plugin`
 
-You can use the `libdir` configuration option to add directories to the
+You can use the `libdirs` and/or `libdir` configuration options to add
+directories to the
 search path. For example, if you set `libdir` to `/home/you/.ikiwiki/`,
-then ikiwiki will look for plugins in `/home/you/.ikiwiki/IkiWiki/Plugin`. This
-configuration option can be either a string (for backward compatibility) or a
-list of strings (to add several directories to the search path).
+then ikiwiki will look for plugins in `/home/you/.ikiwiki/IkiWiki/Plugin`.
 
 Ikiwiki also supports plugins that are external programs. These are
 typically written in some other language than perl. Ikiwiki searches for
-these in `/usr/lib/ikiwiki/plugins` by default. If `libdir` is set, it will
-also look under that directory, for example in `/home/you/.ikiwiki/plugins`.
+these in `/usr/lib/ikiwiki/plugins` by default. If `libdirs` or `libdir` are
+set, it will also look under those directories, for example in
+`/home/you/.ikiwiki/plugins`.
 Note that this type of plugin has to be executable for ikiwiki to use it.