summaryrefslogtreecommitdiff
path: root/lib/WebCoso/File.pm
blob: 1a75e98e9d57a2bdac293a1299edd5b6cb6167fd (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
# -*- mode: perl6 -*- 
class WebCoso::File {
    has Str $.path;
    has $.lang;
    has $!contents;
 
    multi method new($self$path) {
        $self.bless(:$path);
    }
 
    submethod BUILD(:$lang, Str(Cool) :$!path) {
        $!lang = $lang.Str if $lang.defined;
    }
 
    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;
    }
}