Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
Squatting::On::ContinuUser3Contributed Perl DocumeSquatting::On::Continuity(3)

       Squatting::On::Continuity - use Continuity as the server	for your
       Squatting app

       Running a Squatting application on top of Continuity:

	 use App 'On::Continuity';
	 App->continue(port => 2012);

       The purpose of this module is to	add a "continue" method	to your	app
       that will start a Continuity-based web server when invoked.  To use
       this module, pass the string 'On::Continuity' to	the "use" statement
       that loads your Squatting app.

   Continuity meets MVC	(or just VC, actually)

       This method starts a Continuity-based web server.  The %options are
       passed straight through to Continuity, and they let you specify things
       like what port to run the server	on.

   The Special Powers of Continuity
       Continuity has 2	highly unusual (but useful) capabilities.

       1. It can hold many simultaneous	HTTP connections open.
       2. It can "pause" execution until the next request comes	in.

       The easiest way to explain this is by example.

   Becoming RESTless
       Consider	this controller	which has an infinite loop in it.

	   Count => [ '/@count'	],
	   get => sub {
	     my	($self)	= @_;
	     my	$cr	= $self->cr;
	     my	$i	= 1;
	     while (1) {
	   continuity => 1,

       Here, the code is dropping down to the Continuity level.	 The $cr
       variable	contains a Continuity::Request object, and with	that in	hand,
       we can try something as audacious as an infinite	loop.  However,	this
       while loop does not spin	out of control and eat up all your CPU.	 The
       "$cr->next" statement will pause	execution of the current coroutine,
       and it will wait	until the next HTTP request to come in.	 Thus, you can
       hit reload multiple times and watch $i increment	each time.

       However,	not just any HTTP request will wake this coroutine up.	To
       make "$cr->next"	stop blocking, a request with the following properties
       will have to come in.

       It has to have the same session_id.
       It has to be for	the same controller.
       It has to be a GET request.

       The key is this line:

	 queue => { get	=> 'name_of_queue' }

       When you're squatting on	Continuity, you're allowed to define your
       controllers with	a "queue" attribute.  It should	contain	a hashref
       where the keys are HTTP methods (in lower case) and the values are
       unique strings that will	be used	internally by Continuity to
       differentiate one queue of requests from	another.

       Every method mentioned in "queue" will be given its own coroutine to
       run in.

   Pausing for Other Events

       For a sneak peak, take a	look at	the Chat application in	the eg/

       Coro, Continuity, Continuity::Mapper, Squatting::Mapper

perl v5.32.0			  2013-01-23	  Squatting::On::Continuity(3)


Want to link to this manual page? Use this URL:

home | help