X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2Fcatbook-code.git;a=blobdiff_plain;f=lib%2FLolCatalyst%2FLite%2FSnippetStore.pm;fp=lib%2FLolCatalyst%2FLite%2FSnippetStore.pm;h=facc6c6dca585873706afe0c9887d9296ca596cb;hp=b5a173598c95398af1b42afbcbdf08e40354790c;hb=28d1f68e20c5bc5dd1581c3d80e6cd617bac59c8;hpb=07c4c36ac30e7e200b163d16d49e6102a1284f59 diff --git a/lib/LolCatalyst/Lite/SnippetStore.pm b/lib/LolCatalyst/Lite/SnippetStore.pm index b5a1735..facc6c6 100644 --- a/lib/LolCatalyst/Lite/SnippetStore.pm +++ b/lib/LolCatalyst/Lite/SnippetStore.pm @@ -1,9 +1,19 @@ package LolCatalyst::Lite::SnippetStore; use Moose; +use aliased 'LolCatalyst::Lite::Snippet'; use namespace::clean -except => 'meta'; has '_snippets' => (is => 'ro', default => sub { [] }); +has '_translator' => ( + is => 'ro', + required => 1, + lazy => 1, + default => sub { + confess "_translator object requested but never supplied" + }, + init_arg => 'translator' +); sub find { my ($self, $id) = @_; @@ -17,9 +27,13 @@ sub all { sub create { my ($self, $new) = @_; - $new->{id} = @{$self->_snippets} + 1; - push(@{$self->_snippets}, $new); - $new; + my $snippet = Snippet->new( + %$new, + id => (@{$self->_snippets} + 1), + translator => $self->_translator + ); + push(@{$self->_snippets}, $snippet); + $snippet; } __PACKAGE__->meta->make_immutable;