| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Eve; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23340
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
35
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
102
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Eve - The web service creation framework written with events in mind. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.06 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Currently Eve supports running web services under Apache2 with |
|
23
|
|
|
|
|
|
|
mod_perl2 using the PSGI protocol. To run a web service you need to |
|
24
|
|
|
|
|
|
|
prepare a configuration file, create a startup script and create a |
|
25
|
|
|
|
|
|
|
PSGI event handler. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 The startup script |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The startup script is required to prepare all needed objects in order |
|
30
|
|
|
|
|
|
|
for the web service to run. To make a "Hello, World!" application we |
|
31
|
|
|
|
|
|
|
need to have a minimal script located in the C folder of the |
|
32
|
|
|
|
|
|
|
installation like this: |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
35
|
|
|
|
|
|
|
use lib::abs '../lib'; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use warnings; |
|
38
|
|
|
|
|
|
|
use strict; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use File::Basename (); |
|
41
|
|
|
|
|
|
|
use File::Spec (); |
|
42
|
|
|
|
|
|
|
use YAML (); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Eve::Registry; |
|
45
|
|
|
|
|
|
|
use Eve::Support; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub main { |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Make sure we are in a sane environment. |
|
50
|
|
|
|
|
|
|
$ENV{MOD_PERL} or die 'not running under mod_perl!'; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $dirname = File::Basename::dirname(__FILE__); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $file_path = File::Spec->catfile($dirname, '../etc/hello.yaml'); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$Eve::Registry::instance = Eve::Registry->new(%{ |
|
57
|
|
|
|
|
|
|
YAML::LoadFile( |
|
58
|
|
|
|
|
|
|
Eve::Support::open(mode => '<', file => $file_path))}); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$Eve::Registry::instance->bind(); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
main(); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 The configuration file |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
As you can see from the startup script example, the application draws |
|
72
|
|
|
|
|
|
|
its initialization parameters from the hello.yaml file which is |
|
73
|
|
|
|
|
|
|
located in the C folder of the installation: |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
base_uri_string: http://example.com/base-uri |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
All keys and values represented in this file will be automatically |
|
78
|
|
|
|
|
|
|
passed to the registry object constructor. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 The event handler |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Last but not least, the PSGI event handler script: |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use utf8; |
|
87
|
|
|
|
|
|
|
use strict; |
|
88
|
|
|
|
|
|
|
use warnings; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
use open qw(:std :utf8); |
|
91
|
|
|
|
|
|
|
use charnames qw(:full); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use Cwd qw(abs_path); |
|
94
|
|
|
|
|
|
|
use File::Spec; |
|
95
|
|
|
|
|
|
|
use Plack::Request; |
|
96
|
|
|
|
|
|
|
use YAML; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use Eve::Event::PsgiRequestReceived; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return sub { |
|
101
|
|
|
|
|
|
|
my $env = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $event = Eve::Event::PsgiRequestReceived->new( |
|
104
|
|
|
|
|
|
|
env_hash => $env, |
|
105
|
|
|
|
|
|
|
event_map => $Eve::Registry::instance->get_event_map()); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
chdir($Eve::Registry::instance->working_dir_string); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$event->trigger(); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return $event->response->get_raw_list(); |
|
112
|
|
|
|
|
|
|
}; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Those scripts must be set as a startup and request event handlers in |
|
115
|
|
|
|
|
|
|
your C apache setting: |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# This is the startup script, it will be run on each apache service |
|
118
|
|
|
|
|
|
|
# start |
|
119
|
|
|
|
|
|
|
PerlPostConfigRequire /var/www/helloworld/bin/startup.pl |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
PerlSetupEnv Off |
|
122
|
|
|
|
|
|
|
SetHandler perl-script |
|
123
|
|
|
|
|
|
|
PerlResponseHandler Plack::Handler::Apache2 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# This is the PSGI request event handler script |
|
126
|
|
|
|
|
|
|
PerlSetVar psgi_app /var/www/dev/eve/bin/http.psgi |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 Layers of the system |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The first layer of the system is the application layer that is |
|
133
|
|
|
|
|
|
|
responsible for assembling all the components and dealing with |
|
134
|
|
|
|
|
|
|
features specific to the type of the built program. It is the entry |
|
135
|
|
|
|
|
|
|
point of the system. This layer operates with the delegation layer. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
The second one is the delegation layer. It is a control delegation |
|
138
|
|
|
|
|
|
|
facility based on a map of controlling events and handling code. For |
|
139
|
|
|
|
|
|
|
example an event of the "blog post entry creation" type could initiate |
|
140
|
|
|
|
|
|
|
delegation of control to quota check and statistics handlers |
|
141
|
|
|
|
|
|
|
independently. This layer operates with the controlling layer and |
|
142
|
|
|
|
|
|
|
could be requested by any other layer. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The third one is the controlling layer. Some applications, like web |
|
145
|
|
|
|
|
|
|
services, could consist of many handling code parts mapped to many |
|
146
|
|
|
|
|
|
|
types of controlling events. Each of the code parts itself could |
|
147
|
|
|
|
|
|
|
resemble the MVC pattern controller component for example. So to post |
|
148
|
|
|
|
|
|
|
a new blog post entry we might need to call a blog post creation |
|
149
|
|
|
|
|
|
|
handler as an original MVC controller. This layer operates with the |
|
150
|
|
|
|
|
|
|
enterprise layer. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The forth one is the enterprise layer. It might be represented as the |
|
153
|
|
|
|
|
|
|
model and view parts of MVC pattern components interacting with each |
|
154
|
|
|
|
|
|
|
other. In case of the blog posting example the model is a set of |
|
155
|
|
|
|
|
|
|
objects representing a blog and the view is a template engine |
|
156
|
|
|
|
|
|
|
interface that is responsible for building output. This layer operates |
|
157
|
|
|
|
|
|
|
with the tools layer. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The fifth is the environmental layer. It includes things like database |
|
160
|
|
|
|
|
|
|
adaptation code, external systems integration, template and output |
|
161
|
|
|
|
|
|
|
engines internals. It interacts with databases, web services, |
|
162
|
|
|
|
|
|
|
operation system and other external information sources. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 Registry of services |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The Inversion of Control is used as a base framework components |
|
167
|
|
|
|
|
|
|
manipulation principle. It is reflected on the system as a registry of |
|
168
|
|
|
|
|
|
|
services. A service is a definition of how the component should be |
|
169
|
|
|
|
|
|
|
implemented and instantiated and which other components it depends on. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
There is a central registry of the framework that contains generic |
|
172
|
|
|
|
|
|
|
services. Also every subsystem has its own registry that the central |
|
173
|
|
|
|
|
|
|
one refers to. So we have a hierarchical structure where we can |
|
174
|
|
|
|
|
|
|
conveniently manage implementations without affecting the problem |
|
175
|
|
|
|
|
|
|
specific parts. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 Controlling events |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Another technique we use to favor better decoupling of the components |
|
180
|
|
|
|
|
|
|
is the Event-driven approach. There are three entities in the |
|
181
|
|
|
|
|
|
|
implemented concept - an event itself, an event handler and the |
|
182
|
|
|
|
|
|
|
mapping facility to map events to handlers. One event could be |
|
183
|
|
|
|
|
|
|
inherited from another. This inheritance is used when triggering |
|
184
|
|
|
|
|
|
|
events so the derivative will be triggered by handlers listening for |
|
185
|
|
|
|
|
|
|
its ancestors. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 Enterprise modeling |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The modeling infrastructure of the framework is based on a set of |
|
190
|
|
|
|
|
|
|
simple data objects managed by a set of model classes. The data |
|
191
|
|
|
|
|
|
|
objects are simple field containers with service behavior injections |
|
192
|
|
|
|
|
|
|
like serialization/deserialization. The domain logic is encapsulated |
|
193
|
|
|
|
|
|
|
in the model classes. For example a blog post object having a title |
|
194
|
|
|
|
|
|
|
and text fields is a data object and blogging is a model class |
|
195
|
|
|
|
|
|
|
implementing such functionality as appending new post, listing blog |
|
196
|
|
|
|
|
|
|
entries, etc. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The model classes interact with a persistence layer through data |
|
199
|
|
|
|
|
|
|
gateways. These gateways implement data level functionality |
|
200
|
|
|
|
|
|
|
adaptation. For example the comments gateway could implement select, |
|
201
|
|
|
|
|
|
|
insert, update and delete operations for the comments database table |
|
202
|
|
|
|
|
|
|
and transform data rows into comment data objects and vice versa. As |
|
203
|
|
|
|
|
|
|
data gateways are differentiated based on data storage logic they can |
|
204
|
|
|
|
|
|
|
be used by different model classes. For example comments gateway can |
|
205
|
|
|
|
|
|
|
be used by blogging model and activity stream model. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 Running an application |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
When building an application first of all we need to create the |
|
210
|
|
|
|
|
|
|
application script. The script itself should create a registry |
|
211
|
|
|
|
|
|
|
instance, map events to their handlers, setup other application |
|
212
|
|
|
|
|
|
|
specific stuff and generate the initial event. |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 AUTHOR |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Sergey Konoplev, C<< >> |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Igor Zinovyev, C<< >> |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 BUGS |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
223
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
224
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 SUPPORT |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
perldoc Eve |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
You can also look for information at: |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=over 4 |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
L |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
L |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
L |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * Search CPAN |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
L |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=back |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Copyright 2009-2013 Igor Zinovyev, Sergey Konoplev. |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
267
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
268
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
1; |