1. role CompUnit::Repository::Locally {
  2. has Lock $!lock;
  3. has IO::Path $.prefix is required;
  4. has Str $.WHICH;
  5. method new(CompUnit::Repository::Locally: Str:D :$prefix, CompUnit::Repository :$next-repo, *%args) {
  6. my $abspath := $*SPEC.rel2abs($prefix);
  7. my $IO := $abspath.IO;
  8. state %instances;
  9. my $WHICH = self.^name ~ '|' ~ $abspath;
  10. %instances{$WHICH} //=
  11. self.bless(:prefix($IO), :lock(Lock.new), :$WHICH, :$next-repo, |%args);
  12. }
  13. multi method Str(CompUnit::Repository::Locally:D:) { $!prefix.absolute }
  14. multi method gist(CompUnit::Repository::Locally:D:) {
  15. self.path-spec
  16. }
  17. multi method perl(CompUnit::Repository::Locally:D:) {
  18. $?CLASS.perl ~ '.new(' ~ $!prefix.absolute.perl ~ ')';
  19. }
  20. multi method WHICH(CompUnit::Repository::Locally:D:) { $!WHICH }
  21. method path-spec(CompUnit::Repository::Locally:D:) {
  22. self.short-id ~ '#' ~ $!prefix.absolute;
  23. }
  24. method source-file(Str $name --> IO::Path:D) {
  25. self.prefix.add($name)
  26. }
  27. method prefix { "{$!prefix}".IO }
  28. method id() {
  29. my $name = self.path-spec;
  30. $name ~= ',' ~ self.next-repo.id if self.next-repo;
  31. return nqp::sha1($name);
  32. }
  33. # stubs
  34. method short-id(CompUnit::Repository::Locally:D:) {...}
  35. }