f799f709499b305789f9bce30b3da2d48d0b0b06
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Core.pm
1 package App::SCS::Plugin::Core;
2
3 use Moo;
4 no warnings::illegalproto;
5 use Safe::Isa;
6
7 with 'App::SCS::Role::Plugin';
8
9 has templates => (is => 'lazy');
10
11 sub _build_templates {
12   my ($self) = @_;
13   return use_module('App::SCS::PageSet')->new(
14     base_dir => io->dir($self->app->config->{share_dir})->catdir('templates'),
15   );
16 }
17
18 has includes => (is => 'lazy');
19
20 sub _build_includes {
21   my ($self) = @_;
22   return use_module('App::SCS::PageSet')->new(
23     base_dir => io->dir($self->app->config->{share_dir})->catdir('includes'),
24   );
25 }
26
27 sub page_plugins {
28   my ($self) = @_;
29   PageList => 'App::SCS::Plugin::Core::PagePlugin::PageList',
30   Template => {
31     class => 'App::SCS::Plugin::Core::PagePlugin::Template',
32     config => { templates => $self->templates },
33   },
34   Include => {
35     class => 'App::SCS::Plugin::Core::PagePlugin::Include',
36     config => { includes => $self->includes },
37   },
38   PageData => 'App::SCS::Plugin::Core::PagePlugin::PageData',
39 }
40
41 sub default_page_plugins {
42   Template => {
43     name => 'layout',
44   },
45   PageData => {},
46 }
47
48 sub page_dispatchers {
49   my ($self) = @_;
50   sub (/) {
51     $self->pages->get({ path => 'index' });
52   },
53   sub (/**) {
54     [ 302, [ 'Location' => "/$_[1]/" ], [] ]
55   },
56   sub (/**:path/) {
57     $self->pages->get({ %_ })
58   },
59   sub () {
60     $self->pages
61          ->get({ path => 'error_404' })
62          ->$_call_if_object(with_plugin_config => Status => 404);
63   },
64 }
65
66 1;