Commit | Line | Data |
9f2b6cc8 |
1 | package DBIx::Data::Collection::Set::IndexableBy; |
2 | |
3 | use Moose; |
4 | use Method::Signatures::Simple; |
5 | |
6 | extends 'DBIx::Data::Collection::Set'; |
7 | |
8 | has _indexed_by => (is => 'ro', default => sub { {} }); |
9 | |
10 | has _indexable_by => (is => 'ro', required => 1, init_arg => 'indexable_by'); |
11 | |
12 | method 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 | |
24 | 1; |