summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-07-02 17:33:37 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-07-02 18:22:49 -0400
commitc150590e275b21945bc50eeecf4331c48252f6f2 (patch)
tree06bcfb99fa4ce9a7a39c4907a94f022331d1c422
parent84e6c4fa665703133b5778e92c045897df496e97 (diff)
factor out glob2re
-rw-r--r--IkiWiki.pm15
-rw-r--r--IkiWiki/Plugin/attachment.pm6
-rw-r--r--IkiWiki/Plugin/meta.pm4
3 files changed, 11 insertions, 14 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index d9b3dcdb4..c7328e427 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -1290,6 +1290,13 @@ sub pagespec_valid ($) { #{{{
my $sub=pagespec_translate($spec);
return ! $@;
} #}}}
+
+sub glob2re ($) { #{{{
+ my $re=quotemeta(shift);
+ $re=~s/\\\*/.*/g;
+ $re=~s/\\\?/./g;
+ return $re;
+} #}}}
package IkiWiki::FailReason;
@@ -1337,12 +1344,8 @@ sub match_glob ($$;@) { #{{{
$glob="$from/$glob" if length $from;
}
- # turn glob into safe regexp
- $glob=quotemeta($glob);
- $glob=~s/\\\*/.*/g;
- $glob=~s/\\\?/./g;
-
- if ($page=~/^$glob$/i) {
+ my $regexp=glob2re($glob);
+ if ($page=~/^$regexp$/i) {
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index 5d918c43f..1bcf5a2e4 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -318,11 +318,7 @@ sub match_mimetype ($$;@) { #{{{
$mimetype="unknown";
}
- # turn glob into a safe regexp
- my $regexp=quotemeta($wanted);
- $regexp=~s/\\\*/.*/g;
- $regexp=~s/\\\?/./g;
-
+ my $regexp=IkiWiki::glob2re($wanted);
if ($mimetype!~/^$regexp$/i) {
return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
}
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index 8e1b11859..671060fbf 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -253,9 +253,7 @@ sub match { #{{{
my $page=shift;
# turn glob into a safe regexp
- my $re=quotemeta(shift);
- $re=~s/\\\*/.*/g;
- $re=~s/\\\?/./g;
+ my $re=IkiWiki::glob2re(shift);
my $val;
if (exists $pagestate{$page}{meta}{$field}) {