From d2c9fbddc444988c7c391258b764b5f3b30fb5b7 Mon Sep 17 00:00:00 2001
From: Julian Blake Kongslie <jblake@omgwallhack.org>
Date: Tue, 12 Oct 2010 22:21:06 -0700
Subject: More constraints.

---
 usr/src/libpiny/lib/Piny/Config.pm | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

(limited to 'usr/src/libpiny/lib')

diff --git a/usr/src/libpiny/lib/Piny/Config.pm b/usr/src/libpiny/lib/Piny/Config.pm
index a162e2a..4d63c32 100644
--- a/usr/src/libpiny/lib/Piny/Config.pm
+++ b/usr/src/libpiny/lib/Piny/Config.pm
@@ -21,6 +21,30 @@ subtype 'GitBool'
   => message { 'Not correct format for a git-compatible boolean.' }
   ;
 
+subtype 'Path'
+  => as 'Str'
+  => where { $_ =~ /^\// and -e $_ }
+  => message { 'Not an absolute path, or does not exist.' }
+  ;
+
+subtype 'PathDir'
+  => as 'Path'
+  => where { -d $_ }
+  => message { 'Not a directory.' }
+  ;
+
+subtype 'HttpUrl'
+  => as 'Str'
+  => where { $_ =~ /^http:\/\//i }
+  => message { 'Not a http:// URL.' }
+  ;
+
+subtype 'HttpsUrl'
+  => as 'Str'
+  => where { $_ =~ /^https:\/\//i }
+  => message { 'Not a https:// URL.' }
+  ;
+
 # Attributes
 
 has 'confpath' =>
@@ -178,11 +202,11 @@ sub tweakable {
 
 # The tweakables
 
-tweakable "piny_ikiwikidestdir"         => "/srv/www/piny.be/", 'Str';
-tweakable "piny_ikiwikisrcdir"          => "/srv/ikiwiki/", 'Str';
-tweakable "piny_ikiwikiurl"             => "http://piny.be/", 'Str';
-tweakable "piny_ikiwikisecureurl"       => "https://secure.piny.be/", 'Str';
-tweakable "piny_ikiwikisecurepath"      => "/srv/www/secure.piny.be/", 'Str';
+tweakable "piny_ikiwikidestdir"         => "/srv/www/piny.be/", 'PathDir';
+tweakable "piny_ikiwikisrcdir"          => "/srv/ikiwiki/", 'PathDir';
+tweakable "piny_ikiwikiurl"             => "http://piny.be/", 'HttpUrl';
+tweakable "piny_ikiwikisecureurl"       => "https://secure.piny.be/", 'HttpsUrl';
+tweakable "piny_ikiwikisecurepath"      => "/srv/www/secure.piny.be/", 'PathDir';
 tweakable "receive_denyNonFastforwards" => "true", 'GitBool';
 
 # Moose boilerplate
-- 
cgit v1.2.3