I'm still playing around with POE - it seems to be the answer to my
problems: I have built a state-maintaining web demonstrator in a couple
of days - lovely!
I can't determine the answer to my question form the docs, though I
think I understand it...
Am I right in thinking that POE, by default, timeslices parts of a
single "process" - it does not fork a child process for each session.
Yes?
Assuming this, can anyone give me pointers in converting this
session-based system to the Run Wheel:
------- Start code -----------
#!/home/cpan/bin/perl
use POE::Component::Server::HTTP;
use POE;
use POE::Session;
POE::Component::Server::HTTP->new(
Port => 65501,
ContentHandler => {
'/' => sub {
$poe_kernel->post(MyHandler => 'handler', @_);
return RC_WAIT;
} ## end sub
}
);
POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->alias_set('MyHandler');
$_[HEAP] = {};
},
handler => sub {
my ($kernel, $heap, $req, $resp) = @_[KERNEL, HEAP, ARG0,
ARG1];
# find session ID in $req, put in $sessionID
# >sniped code<
unless ($sessionID) {
# no $sessionID passed in
# generate a new sessionID somehow
$sessionID = Apache::Session::Generate::MD5::generate();
# >note sessionID<
# We use a reference to an anonymous hash for passing
# everthing around. !!NOTE!! this means playing with
# the origional data, not a copy of it!!
# >snip stuff to set up $data_ref<
} elsif (not $heap->{$sessionID}) {
# $sessionID passed in, but not in the heap
# this is effectively a new session
# >note sessionID<
# We use a reference to an anonymous hash for passing
# everthing around. !!NOTE!! this means playing with
# the origional data, not a copy of it!!
# >snip stuff to set up $data_ref<
} else {
# this is a repeat request, so recover the data.
$data_ref = $heap->{$sessionID};
# >snip more stuff to set up $data_ref<
} ## end else
# Generate the response
$resp->code(RC_OK);
$resp->content_type('text/html');
$resp->add_content(&make_page($data_ref));
# save some data for next request
$heap->{$sessionID} = $data_ref;
# this causes the response to finaly be sent to the client
$resp->continue();
} ## end sub
}
);
$poe_kernel->run();
exit;
#################################
sub make_page {
# get the real reference to the data.
my $session_heap = shift;
my $page;
$page .= $cgi->h2('demo image viewer');
# >snip lots of stuff on creating a web page<
return $page;
} ## end sub make_page
#######################
# Parse content. Content may come from GET or POST requests. Also
# adapted from Lincoln Stein's CGI.pm.
sub parse_content {
my $content = shift;
my %content;
foreach (split (/[&;]/, $content)) {
# >snip the actual routines<
} ## end foreach (split (/[&;]/, $content...
return \%content;
} ## end sub parse_content
##############################
# >snip support routines for 'parse_content'<
------- Start code -----------
--
--==++
Ian Stuart: Edinburgh University Data Library.
Information is not knowledge
Knowledge is not wisdom
Wisdom is not truth
Truth is not beauty
Beauty is not love
Love is not music
-- Mary.
Personal web site: http://lucas.ucs.ed.ac.uk/