-
Notifications
You must be signed in to change notification settings - Fork 0
/
OokOok.pm
218 lines (162 loc) · 5.47 KB
/
OokOok.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use CatalystX::Declare;
use 5.012;
# PODNAME: OokOok
# ABSTRACT: Temporal Content and Data Management System
=head1 SYNOPSIS
script/ookook_server.pl
=head1 DESCRIPTION
OokOok is a platform for creating scholarly web-based projects.
=cut
application OokOok
with ConfigLoader
with Static::Simple
with Unicode::Encoding
with Params::Nested
with Session
with Session::Store::FastMmap
with Session::State::Cookie
#with Session::PerUser
with StatusMessage
with StackTrace
with OokOok::Authentication
{
use CatalystX::RoleApplicator;
use DateTime;
__PACKAGE__ -> apply_request_class_roles(qw[
Catalyst::TraitFor::Request::REST::ForBrowsers
]);
=head1 CONFIGURATION
In addition to the standard Catalyst configuration options, OokOok has the
following sections.
=head2 TagLibs
The C<TagLibs> section lets you configure the Perl modules that provide
implementations for tag libraries. These tag libraries need additional
configuration in the database before they can be used in projects or
themes.
For example:
<TagLibs>
<module OokOok::TagLibrary::Core>
namepsace uin:uuid:ypUv1ZbV4RGsjb63Mj8b
</module>
</TagLibs>
=cut
__PACKAGE__->config(
name => 'OokOok',
# Disable deprecated behavior needed by old applications
disable_component_resolution_regex_fallback => 1,
enable_catalyst_header => 1, # Send X-Catalyst header
encoding => 'UTF-8',
default_view => 'Mason',
'Plugin::ConfigLoader' => {
file => __PACKAGE__ -> path_to( 'conf' ),
},
);
=method transaction_guard ()
Returns a guard object. If the object goes out of scope before its
C<commit> method is called, then the transaction will be rolled back.
This only works with the PostgreSQL database for now.
=cut
method transaction_guard {
$self -> model('DB') -> txn_scope_guard;
}
=method prepare_path ()
OokOok will check the first component of the request path. If it
is C<dev>, then the request is marked as pertaining to the development
version of the resource, asset, or page. If it is a sequence of
fourteen (14) digits, then it is parsed as a date and time
(yyyymmddhhmmss) indicating the date and time of the version of the
resource, asset, or page.
If the first component is neither C<dev> nor a date and time, then the
path is left unchanged.
=cut
#my $formatter = OokOok::DateTime::Parser -> new;
override prepare_path ($ctx:) {
super;
my @path_chunks = split m[/], $ctx->request->path, -1;
return unless @path_chunks;
my $first = shift @path_chunks;
given($first) {
when('dev') {
$ctx -> stash -> {mode} = 'development';
# Update request base to include whatever
# was stripped from the request path:
my $base = $ctx->request->base;
$base->path($base->path . $first);
}
when('timegate') {
$ctx -> stash -> {mode} = 'timegate';
# if HEAD/GET, then we want to look for Accept-Datetime header
}
when('timemap') {
$ctx -> stash -> {mode} = 'timemap';
# if HEAD/GET, then we want to look for Accept-Datetime header?
}
default {
if(length($first) == 14 && $first =~ m{^\d+$}) {
$ctx -> stash -> {mode} = 'dated';
$ctx -> stash -> {date} = OokOok::DateTime::Parser -> parse_datetime($first);
$ctx -> stash -> {date} -> set_formatter('OokOok::DateTime::Parser');
$ctx -> response -> header( 'Momento-Datetime' => $ctx -> stash -> {date} -> strftime("%a, %d %b %Y %H:%M:%S %z") );
}
else {
$ctx -> stash -> {mode} = 'current';
#$ctx -> stash -> {date} = DateTime -> now;
#$ctx -> stash -> {date} -> set_formatter('OokOok::DateTime::Parser');
unshift @path_chunks, $first;
$first = '';
}
# Update request base to include whatever
# was stripped from the request path:
my $base = $ctx->request->base;
$base->path($base->path . $first);
}
}
# Create a request path from the remaining chunks:
my $path = join('/', @path_chunks) || '/';
# Stuff modified request path back into request:
$ctx->request->path($path);
}
=method formatters ()
Returns the list of formatter classes available.
=cut
our @FORMATTERS;
our @TAGLIBRARIES;
method formatters (Object|ClassName $self:) {
return @FORMATTERS if @FORMATTERS;
@FORMATTERS = $self -> _formatters;
}
method taglibraries (Object|ClassName $self:) {
return @TAGLIBRARIES if @TAGLIBRARIES;
@TAGLIBRARIES = $self -> _taglibs;
for my $taglib (@TAGLIBRARIES) {
if($self -> config -> {TagLibs} -> {module} -> {$taglib} -> {namespace}){
$taglib -> meta -> taglib_namespace(
$self -> config -> {TagLibs} -> {module} -> {$taglib} -> {namespace}
);
}
}
@TAGLIBRARIES;
}
}
BEGIN {
package OokOok;
use OokOok::DateTime::Parser ();
use Module::Pluggable (search_path => 'OokOok::Formatter',
sub_name => '_formatters',
require => 1,
max_depth => 3);
use Module::Pluggable (search_path => 'OokOok::TagLibrary',
sub_name => '_taglibs',
require => 1,
max_depth => 4);
__PACKAGE__ -> _formatters;
__PACKAGE__ -> _taglibs;
#print STDERR "Formatters: \n ", join("\n ", __PACKAGE__ -> _formatters), "\n";
}
1;
__END__
=head1 SEE ALSO
=for :list
* L<OokOok::Controller::Root>
* L<Catalyst>
=cut