1 |
dpavlin |
1 |
package SysIface; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use base 'Mojolicious'; |
7 |
|
|
|
8 |
|
|
our $VERSION = '0.1'; |
9 |
|
|
|
10 |
|
|
# This method will run for each request |
11 |
|
|
sub dispatch { |
12 |
|
|
my ($self, $c) = @_; |
13 |
|
|
|
14 |
|
|
# Try to find a static file |
15 |
|
|
my $done = $self->static->dispatch($c); |
16 |
|
|
|
17 |
|
|
# Use routes if we don't have a response yet |
18 |
|
|
$done ||= $self->routes->dispatch($c); |
19 |
|
|
|
20 |
|
|
# Nothing found, serve static file "public/404.html" |
21 |
|
|
$self->static->serve_404($c) unless $done; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
# This method will run once at server start |
25 |
|
|
sub startup { |
26 |
|
|
my $self = shift; |
27 |
|
|
|
28 |
|
|
# Routes |
29 |
|
|
my $r = $self->routes; |
30 |
|
|
|
31 |
|
|
# Default route |
32 |
|
|
$r->route('/:controller/:action/:id') |
33 |
|
|
->to(controller => 'example', action => 'welcome', id => 1); |
34 |
|
|
|
35 |
|
|
# Use our own context class |
36 |
|
|
$self->ctx_class('SysIface::Context'); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
1; |