aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/Common.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WebCoso/Common.pm')
-rw-r--r--lib/WebCoso/Common.pm46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/WebCoso/Common.pm b/lib/WebCoso/Common.pm
new file mode 100644
index 0000000..0680550
--- /dev/null
+++ b/lib/WebCoso/Common.pm
@@ -0,0 +1,46 @@
+package WebCoso::Common;
+
+our $SRCPATH='src';
+our $DSTPATH='dst';
+our $DSTBASEURL='/';
+
+sub langOf {
+ my ($name)=@_;
+ $name=~m{(^|/)document\.([^.]+)(\.|$)} and return $2;
+ return;
+}
+
+sub typeOf {
+ my ($name)=@_;
+ $name=~m{(^|/)document\.[^.]+\.([^.]+\.[^.]+)$} and return $2;
+ return;
+}
+
+sub typedAs {
+ my ($name,$newtype)=@_;
+ $name=~s{(^|/)(document\.[^.]+\.)([^.]+\.[^.]+)$}{$1$2$newtype};
+ return $name;
+}
+
+sub dstUriFor {
+ my ($name,$short)=(@_,1);
+ warn "dstUriFor($name,$short)\n";
+ if ($short) {
+ $name=~s{/[^/]+$}{/};
+ }
+ else {
+ $name=typedAs($name,'html');
+ }
+ $name=~s{^\Q$SRCPATH\E/}{$DSTBASEURL};
+ return $name;
+}
+
+sub isLang {
+ my ($lang,$name)=@_;
+ warn "isLang($lang,$name)\n";
+ return 1 if $name=~m{/$}; # assume that MultiViews on the server will work
+ return 1 if langOf($name) eq $lang;
+ return;
+}
+
+1;