switch snippets across to object based
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / SnippetStore.pm
CommitLineData
a90d5246 1package LolCatalyst::Lite::SnippetStore;
2
3use Moose;
28d1f68e 4use aliased 'LolCatalyst::Lite::Snippet';
a90d5246 5use namespace::clean -except => 'meta';
6
7has '_snippets' => (is => 'ro', default => sub { [] });
28d1f68e 8has '_translator' => (
9 is => 'ro',
10 required => 1,
11 lazy => 1,
12 default => sub {
13 confess "_translator object requested but never supplied"
14 },
15 init_arg => 'translator'
16);
a90d5246 17
18sub find {
19 my ($self, $id) = @_;
20 $self->_snippets->[$id - 1];
21}
22
23sub all {
24 my ($self) = @_;
25 @{$self->_snippets};
26}
27
28sub create {
29 my ($self, $new) = @_;
28d1f68e 30 my $snippet = Snippet->new(
31 %$new,
32 id => (@{$self->_snippets} + 1),
33 translator => $self->_translator
34 );
35 push(@{$self->_snippets}, $snippet);
36 $snippet;
a90d5246 37}
38
39__PACKAGE__->meta->make_immutable;
40
411;