Commit | Line | Data |
632f0e07 |
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]}) { |
f50b4a35 |
28 | $conf = { base => $_[1], %$conf }; |
632f0e07 |
29 | $self->_feed_http_response(200 => $conf => $_[-1]); |
30 | } |
31 | }, |
32 | } |
33 | |
34 | sub provides_pages { |
35 | my ($self) = @_; |
36 | my $base = $self->mount_at; |
37 | return map "/${base}/$_/", keys %{$self->config}; |
38 | } |
39 | |
40 | 1; |