line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eidolon::Application; |
2
|
|
|
|
|
|
|
# ============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Eidolon |
5
|
|
|
|
|
|
|
# Copyright (c) 2009, Atma 7 |
6
|
|
|
|
|
|
|
# --- |
7
|
|
|
|
|
|
|
# Eidolon/Application.pm - application class |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# ============================================================================== |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
24378
|
use Eidolon::Core::Exceptions; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
12
|
1
|
|
|
1
|
|
653
|
use Eidolon::Core::Registry; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
13
|
1
|
|
|
1
|
|
566
|
use Eidolon::Core::Loader; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
14
|
1
|
|
|
1
|
|
597
|
use Eidolon::Core::CGI; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
33
|
|
15
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
16
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = "0.02"; # 2009-05-12 05:12:54 |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# application interface types |
21
|
|
|
|
|
|
|
use constant |
22
|
|
|
|
|
|
|
{ |
23
|
1
|
|
|
|
|
478
|
"TYPE_CGI" => 0, |
24
|
|
|
|
|
|
|
"TYPE_FCGI" => 1 |
25
|
1
|
|
|
1
|
|
5
|
}; |
|
1
|
|
|
|
|
2
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
28
|
|
|
|
|
|
|
# \% new() |
29
|
|
|
|
|
|
|
# constructor |
30
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
31
|
|
|
|
|
|
|
sub new |
32
|
|
|
|
|
|
|
{ |
33
|
1
|
|
|
1
|
1
|
1260
|
my ($class, $self); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
$class = shift; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
2
|
$self = {}; |
38
|
1
|
|
|
|
|
2
|
bless $self, $class; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
44
|
|
|
|
|
|
|
# start($type) |
45
|
|
|
|
|
|
|
# start the application |
46
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
47
|
|
|
|
|
|
|
sub start |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $type, $r, $config); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
($self, $type) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$name = ref $self; |
54
|
0
|
0
|
|
|
|
|
$type = TYPE_CGI unless defined $type; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->new; |
57
|
0
|
|
|
|
|
|
$config = "$name\::Config"; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# load config |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
local $SIG{"__DIE__"} = sub {}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
eval "require $config"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
throw CoreError::Compile($@) if $@; |
66
|
0
|
|
|
|
|
|
$r->config( $config->new($name, $type) ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
70
|
|
|
|
|
|
|
# handle_request() |
71
|
|
|
|
|
|
|
# handle HTTP request |
72
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
73
|
|
|
|
|
|
|
sub handle_request |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
1
|
|
my ($self, $r, $e, $ctrl, $handler, $router); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self = shift; |
78
|
0
|
|
|
|
|
|
$r = Eidolon::Core::Registry->get_instance; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
eval |
81
|
0
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
local $SIG{"__DIE__"} = sub |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
0
|
|
0
|
|
|
$_[0]->rethrow if ($_[0] eq "Eidolon::Core::Exception"); |
85
|
0
|
|
|
|
|
|
throw CoreError($_[0]); |
86
|
0
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# some useful classes |
89
|
0
|
|
|
|
|
|
$r->cgi ( Eidolon::Core::CGI->new ); |
90
|
0
|
|
|
|
|
|
$r->loader( Eidolon::Core::Loader->new ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# load drivers specified in config |
93
|
0
|
|
|
|
|
|
foreach (@{ $r->config->{"drivers"} }) |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
$r->loader->load |
96
|
|
|
|
|
|
|
( |
97
|
|
|
|
|
|
|
$_->{"class"}, |
98
|
0
|
0
|
|
|
|
|
exists $_->{"params"} ? @{ $_->{"params"} } : () |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# get a router |
103
|
0
|
|
|
|
|
|
$router = $r->loader->get_object("Eidolon::Driver::Router"); |
104
|
0
|
0
|
|
|
|
|
throw CoreError::NoRouter unless $router; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# find and start a request handler |
107
|
0
|
|
|
|
|
|
$router->find_handler; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
{ |
110
|
1
|
|
|
1
|
|
5
|
no strict "refs"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
197
|
|
|
0
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
&{ $router->get_handler }( @{ $router->get_params || [] } ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# if something went wrong |
116
|
0
|
0
|
|
|
|
|
if ($@) |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
|
|
|
$e = $@; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
throw CoreError::NoErrorHandler($e) unless $r->config->{"app"}->{"error"}; |
121
|
0
|
|
0
|
|
|
|
$ctrl = $r->config->{"app"}->{"error"}->[0] || undef; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
eval "require $ctrl"; |
124
|
0
|
0
|
|
|
|
|
throw CoreError::Compile($@) if $@; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# find the error handler |
127
|
0
|
|
|
|
|
|
$handler = $r->config->{"app"}->{"error"}->[1]; |
128
|
0
|
0
|
|
|
|
|
throw CoreError::NoErrorHandler($e) unless $handler; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$handler = "$ctrl\::$handler"; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
{ |
133
|
1
|
|
|
1
|
|
65
|
no strict "refs"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
108
|
|
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
&{ $handler }( ( $e ) ); |
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# cleanup |
139
|
0
|
|
|
|
|
|
$r->free; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |