-
-
Save ugexe/81ca1c58bbfebff415028efabc3870e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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