factor out glob2re
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 2 Jul 2008 21:33:37 +0000 (17:33 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 2 Jul 2008 21:33:37 +0000 (17:33 -0400)
IkiWiki.pm
IkiWiki/Plugin/attachment.pm
IkiWiki/Plugin/meta.pm

index d9b3dcdb473df66c4505a1b47e429febac493b63..c7328e427c7bdb535aaac3f4c2586d6f6d31c95d 100644 (file)
@@ -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");
                }
index 5d918c43f0551baeb28c4b6b6b03035567e9ea73..1bcf5a2e49e43e55aca07ad8ddb8d885e7cc903f 100644 (file)
@@ -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");
        }
index 8e1b11859fdf4a3bd676d67d8c8a6211adb2c1b1..671060fbfa677e300a1f5ec7036c1488957e88bf 100644 (file)
@@ -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}) {