diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | lib/WebCoso.pm | 31 | ||||
-rw-r--r-- | t/tests/webcoso.t | 27 |
3 files changed, 47 insertions, 13 deletions
@@ -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; |