-
Notifications
You must be signed in to change notification settings - Fork 1
/
Base.pm
118 lines (88 loc) · 1.98 KB
/
Base.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
package Angelos::Engine::Base;
use Angelos::Class;
use Carp ();
use Angelos::Exceptions;
use Angelos::PSGI::Engine;
use Angelos::Request;
use PlackX::Engine;
with 'Angelos::Class::Loggable';
has 'engine' => (
is => 'rw',
handles => [qw(run)],
);
has 'root' => (
is => 'rw',
required => 1,
);
has 'host' => (
is => 'rw',
isa => 'Str',
default => '127.0.0.1',
);
has 'port' => (
is => 'rw',
isa => 'Int',
default => 3000,
);
has 'server' => (
is => 'rw',
default => 'ServerSimple',
);
has 'debug' => (
is => 'rw',
isa => 'Bool',
default => 0
);
has 'request_handler' => (
is => 'rw',
isa => 'CodeRef',
);
has 'config' => ( is => 'rw', );
has 'logger' => (
is => 'rw',
required => 1,
);
has 'app' => ( is => 'rw', );
sub BUILD {
my $self = shift;
$self->engine( $self->build_engine );
}
sub SETUP { }
sub build_engine {
my $self = shift;
my $request_handler = $self->build_request_handler;
my $engine = PlackX::Engine->new(
{ server => {
module => $self->server,
args => {
port => $self->port,
host => $self->host,
},
},
request_handler => $request_handler,
request_class => 'Angelos::Request',
}
);
return $engine;
}
sub build_request_handler {
my $self = shift;
return $self->request_handler if $self->request_handler;
return sub { my $req = shift; $self->handle_request($req) }
}
sub handle_request {
Angelos::Exception::AbstractMethod->throw(
message => 'Sub class must overried this method' );
}
__END_OF_CLASS__
__END__
=head1 NAME
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 AUTHOR
Takatoshi Kitano E<lt>kitano.tk@gmail.comE<gt>
=head1 SEE ALSO
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut