Skip to content

Instantly share code, notes, and snippets.

@ugexe

ugexe/CURI.pm6 Secret

Created July 27, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/81ca1c58bbfebff415028efabc3870e8 to your computer and use it in GitHub Desktop.
Save ugexe/81ca1c58bbfebff415028efabc3870e8 to your computer and use it in GitHub Desktop.
method !lazy-distribution($dist-id, :$meta) {
class :: does Distribution::Locally {
has $.dist-id;
has $.read-dist;
has $!installed-dist;
has $.meta;
method !dist {
unless $!installed-dist.defined {
$!installed-dist = InstalledDistribution.new($.read-dist()(), :$.prefix);
$!meta = $!installed-dist.meta.hash;
}
$!installed-dist;
}
method meta(--> Hash:D) {
my role LazyMetaReader {
has $.meta-reader;
method AT-KEY($key) { $!meta-reader($key) }
method EXISTS-KEY($key) { ?$!meta-reader($key) }
}
$!meta.hash but LazyMetaReader(-> $key { $!meta{$key} // ($!meta = self!dist.meta.hash).{$key} });
}
method content($content-id --> IO::Handle:D) { self!dist.content($content-id) }
method Str() { self!dist.Str }
}.new(
:$dist-id,
:read-dist(-> { self!read-dist($dist-id) }),
:$meta,
:$.prefix,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment