summaryrefslogtreecommitdiff
path: root/lib/WebCoso/File.pm
blob: 764cf2f6a74cc0b6bdbe27a485c2bdb121a86188 (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
# -*- mode: perl6 -*- 
class WebCoso::File {
    has Str $.path;
    has $.lang;
    has $!contents;
 
    multi method new($self$path) {
        $self.bless(:$path);
    }
 
    submethod BUILD(Str(Cool) :$!lang, Str(Cool) :$!path) {}
 
    multi method contents() {
        return $!contents //= $.parse();
    }
    multi method contents($new_contents) {
        return $!contents = $.serialise($new_contents);
    }
 
    method parse() {
        return $.path.IO.slurp();
    }
    method serialise($contents) {
        $.path.IO.spurt($contents);
        return $contents;
    }
 
    method modified() {
        return $.path.IO.modified;
    }
}