1. class CompUnit {
  2. has Str $.from;
  3. has Str $.short-name;
  4. has Version $.version;
  5. has Str $.auth;
  6. has Str $!WHICH;
  7. # The CompUnit::Repository that loaded this CompUnit.
  8. has CompUnit::Repository $.repo is required;
  9. # That repository's identifier for the compilation unit. This is not globally unique.
  10. has Str:D $.repo-id is required;
  11. # The low-level handle.
  12. has CompUnit::Handle $.handle is required;
  13. # Whether the module was loaded from a precompilation or not.
  14. has Bool $.precompiled = False;
  15. # The distribution that this compilation unit was installed as part of
  16. # (if known).
  17. has Distribution $.distribution;
  18. my $default-from = 'Perl6';
  19. method new(CompUnit:U:
  20. Str :$short-name is copy,
  21. Version :$version,
  22. Str :$auth,
  23. Str :$from = $default-from,
  24. CompUnit::Handle :$handle = CompUnit::Handle,
  25. CompUnit::Repository :$repo,
  26. Str :$repo-id,
  27. Bool :$precompiled = False,
  28. Distribution :$distribution,
  29. ) {
  30. self.bless(
  31. :$short-name,
  32. :$version,
  33. :$auth,
  34. :$from,
  35. :$handle,
  36. :$repo,
  37. :$repo-id,
  38. :$precompiled,
  39. :$distribution,
  40. );
  41. }
  42. multi method WHICH(CompUnit:D:) { $!WHICH //= self.^name }
  43. multi method Str(CompUnit:D: --> Str:D) { $!short-name }
  44. multi method gist(CompUnit:D: --> Str:D) { self.short-name }
  45. method unit() {
  46. $.handle.unit
  47. }
  48. }