summaryrefslogtreecommitdiff
path: root/lib/WebCoso/Maker.pm
blob: 91ceb03b65c9fa843327d7393a7a448632203ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- mode: perl6 -*- 
role WebCoso::Maker[$from,$to] {
    has $.wc;
    has $.basename;
    has $.dir;
 
    method process-contents(:$src,:@deps) { ... }
 
    method dest-files() {
        say "Maker[$from,$to]($.dir/$.basename)::dest-files";
        return $.wc.get-files($.dir,$.basename,$to,:!make);
    }
 
    method src-files() {
        say "Maker[$from,$to]($.dir/$.basename)::src-files";
        return $.wc.get-files($.dir,$.basename,$from);
    }
 
    method dep-files() {
        return Hash;
    }
 
    method make() {
        say "Maker[$from,$to]($.dir/$.basename)::make";
        my %srcs = $.src-files();
        my %dsts = $.dest-files();
        my %deps = $.dep-files();
 
        say "Maker[$from,$to]($.dir/$.basename)::make from {%srcs.perl} and {%deps.perl} to {%dsts.perl}";
 
        for %srcs.keys -> $lang {
            my $src = %srcs{$lang};
            my $dst = %dsts{$lang};
            my @deps = %deps{$lang// ();
            say "Maker[$from,$to]($.dir/$.basename)::make lang $lang";
            say "Maker[$from,$to]($.dir/$.basename)::make dst modified {$dst ?? $dst.modified !! 'not-there'} src modified {$src.modified}";
            next if $dst and $dst.modified after
                 all($src.modified,@deps».modified.flat);
 
            say "Maker[$from,$to]($.dir/$.basename)::make processing $lang";
            my $processed-contents = self.process-contents(
                src => $src.slurp,
                deps => @deps».slurp,
            );
 
            # that .Str.IO is a hack to work around 
            # https://rt.perl.org/Public/Bug/Display.html?id=126006 
            %dsts{$lang} = $.wc.put-file($.dir,$.basename,$lang,$to,
                                         $processed-contents).Str.IO;
        }
        return %dsts;
    }
}