| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package EntityModel::Web::NaFastCGI; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: L support for L |
|
3
|
|
|
|
|
|
|
use EntityModel::Class { |
|
4
|
1
|
|
|
|
|
8
|
_isa => [qw(Net::Async::FastCGI)], |
|
5
|
1
|
|
|
1
|
|
1923
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
EntityModel::Web::NaFastCGI - website support for L |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.002 |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use IO::Async::Loop; |
|
20
|
|
|
|
|
|
|
use EntityModel; |
|
21
|
|
|
|
|
|
|
use EntityModel::Template; |
|
22
|
|
|
|
|
|
|
use EntityModel::Web::NaFastCGI; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
|
25
|
|
|
|
|
|
|
my $model = EntityModel->new->load_from(JSON => { file => 'model.json' }); |
|
26
|
|
|
|
|
|
|
my $tmpl = EntityModel::Template->new; |
|
27
|
|
|
|
|
|
|
$tmpl->process_template(\'[% PROCESS TemplateDefs.tt2 %]'); |
|
28
|
|
|
|
|
|
|
my $fcgi = EntityModel::Web::NaFastCGI->new( |
|
29
|
|
|
|
|
|
|
model => $model, |
|
30
|
|
|
|
|
|
|
context_args => [ |
|
31
|
|
|
|
|
|
|
template => $tmpl, |
|
32
|
|
|
|
|
|
|
], |
|
33
|
|
|
|
|
|
|
show_timing => 1, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$loop->add($fcgi); |
|
37
|
|
|
|
|
|
|
$fcgi->listen( |
|
38
|
|
|
|
|
|
|
service => 9738, |
|
39
|
|
|
|
|
|
|
on_listen_error => sub { die "Listen failed: @_"; }, |
|
40
|
|
|
|
|
|
|
on_resolve_error => sub { die "Resolve failed: @_"; } |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
$loop->loop_forever; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
111196
|
use EntityModel::Web::Context; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use EntityModel::Web::NaFastCGI::Request; |
|
50
|
|
|
|
|
|
|
use EntityModel::Web::NaFastCGI::Response; |
|
51
|
|
|
|
|
|
|
use Time::Checkpoint::Sequential; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 configure |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub configure { |
|
58
|
|
|
|
|
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
my %args = @_; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{show_timing} = 0 unless exists $self->{show_timing}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if(my $model = delete $args{model}) { |
|
64
|
|
|
|
|
|
|
$self->{model} = $model; |
|
65
|
|
|
|
|
|
|
($self->{web}) = grep { $_->isa('EntityModel::Web') } $model->plugin->list; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
foreach (qw(show_timing context_args on_request)) { |
|
69
|
|
|
|
|
|
|
if(defined(my $v = delete $args{$_})) { |
|
70
|
|
|
|
|
|
|
$self->{$_} = $v; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return $self->SUPER::configure(%args); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 on_request |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub on_request { |
|
82
|
|
|
|
|
|
|
my ($self, $r) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $check = $self->{show_timing} ? Time::Checkpoint::Sequential->new : undef; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $req = EntityModel::Web::NaFastCGI::Request->new($r); |
|
87
|
|
|
|
|
|
|
$check->mark('Generate request') if $self->{show_timing}; |
|
88
|
|
|
|
|
|
|
$self->maybe_invoke_event('on_request_ready', $self, $req); |
|
89
|
|
|
|
|
|
|
$check->mark('Request callback') if $self->{show_timing}; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $ctx = EntityModel::Web::Context->new( |
|
92
|
|
|
|
|
|
|
request => $req, |
|
93
|
|
|
|
|
|
|
$self->{context_args} |
|
94
|
|
|
|
|
|
|
? (@{$self->{context_args}}) |
|
95
|
|
|
|
|
|
|
: () |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
$check->mark('Context') if $self->{show_timing}; |
|
98
|
|
|
|
|
|
|
$self->maybe_invoke_event('on_context', $self, $ctx); |
|
99
|
|
|
|
|
|
|
$check->mark('Context callback') if $self->{show_timing}; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Do the page lookup immediately |
|
102
|
|
|
|
|
|
|
$ctx->find_page_and_data($self->{web}); |
|
103
|
|
|
|
|
|
|
$check->mark('Find page') if $self->{show_timing}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
unless($ctx->page) { |
|
106
|
|
|
|
|
|
|
$self->maybe_invoke_event('on_page_not_found', $self, $ctx); |
|
107
|
|
|
|
|
|
|
return; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$self->maybe_invoke_event('on_page', $self, $ctx); |
|
111
|
|
|
|
|
|
|
$check->mark('Page callback') if $self->{show_timing}; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Defer the data resolution step |
|
114
|
|
|
|
|
|
|
$self->get_loop->later($self->_capture_weakself(sub { |
|
115
|
|
|
|
|
|
|
my $self = shift; |
|
116
|
|
|
|
|
|
|
$check->reset_timer if $self->{show_timing}; |
|
117
|
|
|
|
|
|
|
$ctx->resolve_data; |
|
118
|
|
|
|
|
|
|
$check->mark('Resolve data') if $self->{show_timing}; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# And also defer actual page generation, in an attempt to make page handling slightly fairer |
|
121
|
|
|
|
|
|
|
$self->get_loop->later(sub { |
|
122
|
|
|
|
|
|
|
$check->reset_timer if $self->{show_timing}; |
|
123
|
|
|
|
|
|
|
my $resp = EntityModel::Web::NaFastCGI::Response->new($ctx, $r); |
|
124
|
|
|
|
|
|
|
$check->mark('Create response') if $self->{show_timing}; |
|
125
|
|
|
|
|
|
|
$self->maybe_invoke_event('on_response', $self, $resp); |
|
126
|
|
|
|
|
|
|
$check->mark('Response callback') if $self->{show_timing}; |
|
127
|
|
|
|
|
|
|
my $rslt = $resp->process; |
|
128
|
|
|
|
|
|
|
$check->mark('Process response') if $self->{show_timing}; |
|
129
|
|
|
|
|
|
|
my $elapsed = 0; |
|
130
|
|
|
|
|
|
|
undef $check; |
|
131
|
|
|
|
|
|
|
printf("200 OK %s\n", $req->path); |
|
132
|
|
|
|
|
|
|
}); |
|
133
|
|
|
|
|
|
|
})); |
|
134
|
|
|
|
|
|
|
return; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub on_page_not_found { |
|
138
|
|
|
|
|
|
|
my $self = shift; |
|
139
|
|
|
|
|
|
|
warn "No page was found\n"; |
|
140
|
|
|
|
|
|
|
return; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |