summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2015-09-05 14:55:28 +0100
committerdakkar <dakkar@thenautilus.net>2015-09-05 14:55:44 +0100
commit4959be2ceea013461f3e8848a4c01263f0362452 (patch)
tree155d7e2eee8a8a7f8e7695a99a21a3cccd3996b1
parentuse attributes, not accessors (diff)
downloadWebCoso-p6-4959be2ceea013461f3e8848a4c01263f0362452.tar.gz
WebCoso-p6-4959be2ceea013461f3e8848a4c01263f0362452.tar.bz2
WebCoso-p6-4959be2ceea013461f3e8848a4c01263f0362452.zip
first test
-rw-r--r--.gitignore2
-rw-r--r--lib/WebCoso.pm31
-rw-r--r--t/tests/webcoso.t27
3 files changed, 47 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index d69566e..8c00e0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
*~
-/t/data/dst/*
+/t/data/
diff --git a/lib/WebCoso.pm b/lib/WebCoso.pm
index 5202745..db60f8f 100644
--- a/lib/WebCoso.pm
+++ b/lib/WebCoso.pm
@@ -1,4 +1,7 @@
# -*- mode: perl6 -*-
+use WebCoso::Doc::Page;
+use WebCoso::Doc::Feed;
+
class WebCoso {
has $.srcdir;
has $.destdir;
@@ -6,31 +9,35 @@ class WebCoso {
has @!docs;
method get-files($dir,$basename,$ext) {
- my %files = gather {
- for my $base ($.srcdir,$!tmpdir) {
- my @files = $base.child($dir).dir(
- test => /$basename \. .+? \. $ext/,
- );
- take map {
- (.name ~~ /$basename \. (.+?) \. $ext/)[0]
+ gather {
+ for $.srcdir,$!tmpdir -> $base {
+ my @files = try {
+ CATCH {
+ when X::IO { }
+ }
+ $base.child($dir).dir(
+ test => /$basename \. .+? \. $ext/,
+ );
+ } // ();
+ take $_ for map {
+ (.basename ~~ /$basename \. (.+?) \. $ext/)[0]
=>
$_
- } @files;
+ }, @files;
}
}
- return %files;
}
method put-file($dir,$basename,$lang,$ext,$contents) {
- $!tmpdir.child($dir).child("${basename}.${lang}.${ext}").spurt($contents);
+ $!tmpdir.child($dir).child("{$basename}.{$lang}.{$ext}").spurt($contents);
return;
}
method new-doc(:$dir) {
- @!docs.push(Document.new(:$dir,wc=>self);
+ @!docs.push(WebCoso::Doc::Page.new(:$dir,wc=>self));
}
method new-feed(:$dir) {
- @!docs.push(Feed.new(:$dir,wc=>self);
+ @!docs.push(WebCoso::Doc::Feed.new(:$dir,wc=>self));
}
method run() {
.make() for @!docs;
diff --git a/t/tests/webcoso.t b/t/tests/webcoso.t
new file mode 100644
index 0000000..48c9917
--- /dev/null
+++ b/t/tests/webcoso.t
@@ -0,0 +1,27 @@
+# -*- mode: perl6 -*-
+use Test;
+use WebCoso;
+
+'t/data/src/one'.IO.mkdir;
+'t/data/dst'.IO.mkdir;
+
+spurt('t/data/src/one/document.it.txt','foo');
+spurt('t/data/src/one/document.en.txt','foo');
+
+my $wc = WebCoso.new(
+ srcdir => 't/data/src'.IO,
+ destdir => 't/data/dst'.IO,
+);
+
+my %one = $wc.get-files('one','document','txt');
+
+is-deeply(
+ %one,
+ {
+ it => 't/data/src/one/document.it.txt'.IO,
+ en => 't/data/src/one/document.en.txt'.IO,
+ },
+ 'get-files works',
+);
+
+done-testing;