/
Locally.pm6
56 lines (45 loc) · 1.46 KB
/
Locally.pm6
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
54
55
56
role CompUnit::Repository::Locally {
has Str $.abspath;
has IO::Path $.prefix is required;
has ValueObjAt $.WHICH is required;
my $lock = Lock.new;
my %instances;
method new(CompUnit::Repository::Locally: Any:D :$prefix is copy) {
my $abspath;
if $prefix ~~ IO::Path {
$abspath := $prefix.abspath;
}
else {
$abspath := $*SPEC.rel2abs($prefix.Str);
$prefix = $abspath.IO;
}
my $WHICH := ValueObjAt.new(self.^name ~ '|' ~ $abspath);
$lock.protect: {
%instances{$WHICH} //= self.bless(:$abspath, :$prefix, :$WHICH, |%_)
}
}
multi method Str(CompUnit::Repository::Locally:D:) { $!abspath }
multi method gist(CompUnit::Repository::Locally:D:) {
self.path-spec
}
multi method perl(CompUnit::Repository::Locally:D:) {
$?CLASS.^name ~ '.new(prefix => ' ~ $!abspath.perl ~ ')';
}
multi method WHICH(CompUnit::Repository::Locally:D:) { $!WHICH }
method path-spec(CompUnit::Repository::Locally:D:) {
self.short-id ~ '#' ~ $!abspath
}
method source-file(Str $name --> IO::Path:D) {
self.prefix.add($name)
}
method id() {
nqp::sha1(
self.next-repo
?? self.path-spec ~ ',' ~ self.next-repo.id
!! self.path-spec
)
}
# stubs
method short-id(CompUnit::Repository::Locally:D:) { ... }
}
# vim: ft=perl6 expandtab sw=4