1. class CompUnit::Repository::Spec {
  2. has $.short-id;
  3. has %.options;
  4. has $.path;
  5. has $.Str;
  6. method from-string(Str:D $spec, :$default-short-id = 'file') {
  7. return unless $spec.chars;
  8. # something we understand
  9. if $spec.contains('#') {
  10. if $spec ~~ /^
  11. <before .>
  12. [
  13. $<type>=[ <.ident>+ % '::' ]
  14. $<options>=[ '#' $<option-name>=\w+
  15. <[ < ( [ { ]> $<option-value>=<[\w-]>+? <[ > ) \] } ]>
  16. ]*
  17. '#'
  18. ]?
  19. $<path>=.*
  20. $/ {
  21. my $short-id := ~($<type> // $default-short-id);
  22. my $path := $*SPEC.canonpath(~$<path>);
  23. self.new(
  24. :$short-id,
  25. :options(%($<option-name>>>.Str Z=> $<option-value>>>.Str)),
  26. :$path
  27. :Str($short-id ~ $<options> ~ '#' ~ $path)
  28. );
  29. }
  30. }
  31. else {
  32. my $path := $*SPEC.canonpath($spec);
  33. self.new(:short-id($default-short-id), :$path, :Str($default-short-id ~ '#' ~ $path))
  34. }
  35. }
  36. }