beginnings of IndexableBy
[dbsrgits/DBIx-Data-Store-old.git] / lib / DBIx / Data / Collection / Set / IndexableBy.pm
CommitLineData
9f2b6cc8 1package DBIx::Data::Collection::Set::IndexableBy;
2
3use Moose;
4use Method::Signatures::Simple;
5
6extends 'DBIx::Data::Collection::Set';
7
8has _indexed_by => (is => 'ro', default => sub { {} });
9
10has _indexable_by => (is => 'ro', required => 1, init_arg => 'indexable_by');
11
12method indexed_by ($by) {
13 if (my $cached = $self->_indexed_by->{$by}) {
14 return $cached
15 }
16 my $index_spec = $self->_indexable_by->{$by};
17 die "${self} not indexable by ${by}" unless $index_spec;
18 my $new = DBIx::Data::Collection::Set->new($index_spec);
19 $self->_indexed_by->{$by} = $new
20}
21
22__PACKAGE__->meta->make_immutable;
23
241;