-
Notifications
You must be signed in to change notification settings - Fork 0
/
Narwhal.pm
84 lines (72 loc) · 1.77 KB
/
Narwhal.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package Narwhal;
use OX;
use MooseX::Types::Path::Class;
with 'OX::Role::WithAppRoot';
has kioku_dsn => (
is => 'ro',
isa => 'Str',
value => 'dbi:SQLite:narwhal.db',
);
has kioku_extra_args => (
is => 'ro',
isa => 'HashRef',
block => sub { { create => 1 } },
);
has template_root => (
is => 'ro',
isa => 'Path::Class::Dir',
coerce => 1,
block => sub { shift->param('app_root')->subdir('root', 'templates') },
dependencies => ['app_root'],
);
has redirect => (
is => 'ro',
isa => 'Narwhal::Component::Redirect',
);
has wiki => (
is => 'ro',
isa => 'Narwhal::Component::Wiki',
dependencies => ['kioku', 'tt'],
);
has wiki_edit => (
is => 'ro',
isa => 'Narwhal::Component::Wiki::Edit',
dependencies => ['kioku', 'tt'],
);
has tt => (
is => 'ro',
isa => 'OX::View::TT',
dependencies => ['template_root'],
);
has kioku => (
is => 'ro',
isa => 'Narwhal::Component::Model',
dependencies => {
dsn => 'kioku_dsn',
extra_args => 'kioku_extra_args',
},
);
router ['Narwhal::RouteBuilder::HTTPMethod'], as {
route '/' => 'redirect.permanent', (
to => '/page/main',
);
route '/page/:page_name' => 'wiki.view', (
page_name => { isa => 'Str' },
);
route '/edit/:page_name' => 'http-method:edit', (
page_name => { isa => 'Str' },
);
route '/page/:page_name/:rev' => 'wiki.view_old', (
page_name => { isa => 'Str' },
rev => { isa => qr/^[0-9a-f]{40}$/ },
);
route '/history/:page_name' => 'wiki.history', (
page_name => { isa => 'Str' },
);
}, (
redirect => depends_on('redirect'),
wiki => depends_on('wiki'),
edit => depends_on('wiki_edit'),
);
no OX;
1;