comment saving
[scpubgit/Commentry.git] / lib / App / Commentry / CommentStore.pm
1 package App::Commentry::CommentStore;
2
3 use aliased 'App::Commentry::CommentSet';
4 use Moo;
5
6 has base_dir => (is => 'ro', required => 1);
7
8 has _cache => (
9   is => 'ro', init_arg => undef,
10   lazy => 1, default => sub { {} },
11   clearer => 'clear_cache'
12 );
13
14 sub get {
15   my ($self, $proto) = @_;
16   my $path = $proto->{path} or die "->get requires a path key";
17   $self->_cache->{$path} ||= do {
18     CommentSet->new(base_dir => $self->base_dir, path => $path)
19   };
20 }
21
22 1;