switch snippets across to object based
[catagits/catbook-code.git] / lib / LolCatalyst / Lite / SnippetStore.pm
index b5a1735..facc6c6 100644 (file)
@@ -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;