initial import of App::SCS code
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Feeds.pm
1 package App::SCS::Plugin::Feeds;
2
3 use Module::Runtime qw(use_module);
4 use Moo;
5
6 with 'App::SCS::Role::Plugin';
7
8 has mount_at => (is => 'ro', default => sub { 'feed' });
9
10 has generator => (
11   is => 'lazy',
12   handles => { _feed_http_response => 'feed_http_response' },
13 );
14
15 sub _build_generator {
16   my ($self) = @_;
17   use_module('App::SCS::Plugin::Feeds::Generator')->new(
18     pages => $self->pages,
19     mounted_at => $self->mount_at,
20   );
21 }
22
23 sub page_dispatchers {
24   my ($self) = @_;
25   my $base = $self->mount_at;
26   "/${base}/**/" => sub {
27     if (my $conf = $self->config->{$_[1]}) {
28       $self->_feed_http_response(200 => $conf => $_[-1]);
29     }
30   },
31 }
32
33 sub provides_pages {
34   my ($self) = @_;
35   my $base = $self->mount_at;
36   return map "/${base}/$_/", keys %{$self->config};
37 }
38
39 1;