Skip to content

Commit f4e236d

Browse files
committed
more random Perl6::Documentable::Registry hackery
1 parent eecc292 commit f4e236d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/Perl6/Documentable/Registry.pm

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@ use v6;
22
use Perl6::Documentable;
33

44
class Perl6::Documentable::Registry {
5-
has @!documentables;
5+
has @.documentables;
6+
has Bool $.composed = False;
7+
has %!cache;
8+
has %!grouped-by
69
method add-new(*%args) {
10+
die "Cannot add something to a composed registry" if $.composed;
711
@!documentables.push: Perl6::Documentable.new(|%args);
812
1;
913
}
14+
method compose() {
15+
$!composed = True;
16+
}
17+
method grouped-by(Str $what) {
18+
die "You need to compose this registry first" unless $.composed;
19+
%!grouped-by ||= @!documentables.classify(*."$what"());
20+
}
21+
method lookup(Str $what, Str :$by!) {
22+
unless %!cache.exists($by) {
23+
for @!documentables -> $d {
24+
%!cache{$by}{$d."$by"()}.push: $d;
25+
}
26+
}
27+
%!cache{$by}{$d};
28+
}
1029
}

0 commit comments

Comments
 (0)