Continuity

 view release on metacpan or  search on metacpan

eg/slowprint.pl  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use lib '../lib';
use Continuity;
use Coro::AnyEvent;

use Coro::Debug;
our $coro_debug_server = new_unix_server Coro::Debug "/tmp/corodebug";

$| = 1;

my $reap_watcher;
sub reaper {
  $reap_watcher = AnyEvent->timer(
    interval => 1,
    cb => sub {
      print "Reap event!\n";
    }

lib/Continuity/Adapt/HttpDaemon.pm  view on Meta::CPAN

sub cached_params { exists $_[1] ? $_[0]->{cached_params} = $_[1] : $_[0]->{cached_params} }

sub debug_level { exists $_[1] ? $_[0]->{debug_level} = $_[1] : $_[0]->{debug_level} }

sub debug_callback { exists $_[1] ? $_[0]->{debug_callback} = $_[1] : $_[0]->{debug_callback} }

=for comment

See L<Continuity::Request> for API documentation.

This is what gets passed through a queue to coroutines when new requests for
them come in. It needs to encapsulate:

*  The connection filehandle
*  CGI parameters cache

XXX todo: understands GET parameters and POST in
application/x-www-form-urlencoded format, but not POST data in
multipart/form-data format.  Use the AsCGI thing if you actually really need
that (it's used for file uploads).
# XXX check request content-type, if it isn't x-form-data then throw an error

lib/Continuity/Adapt/PSGI.pm  view on Meta::CPAN

package Continuity::Adapt::PSGI;

=head1 NAME

Continuity::Adapt::PSGI - PSGI backend for Continuity

=head1 SYNOPSIS

  # Run with on of these:
  #   corona demo.pl
  #   twiggy demo.pl
  #   ./myapp.pl # Will try to fall back to HttpDaemon ;)

  # "Twiggy is a lightweight and fast HTTP server"
  # "Corona is a Coro based Plack web server. It uses Net::Server::Coro under the hood"

  use Continuity;

  my $server = Continuity->new;

lib/Continuity/Inspector.pm  view on Meta::CPAN

Implements the same API as the "Request" objects created by 
L<Continuity::Adapt::HttpDaemon> and other adapters.
These faked request objects go over the request queue but instead of
containing a request from a user, they contain a request from another
part of the system.

Use L<Continuity::Mapper> instead.

=head2 C<< new(callback => sub { ... } ) >>

Call with the code to run in another coroutine's execution context.
The execution context includes the call stack, including all of the data returned by
L<Carp::confess>, L<Padwalker>, L<caller>, and so on.

One Inspector instance can be reused but can only on one context at a time or else
the locking stuff will probably go all breaky.

=cut

sub new {
  my $class = shift;

lib/Continuity/Mapper.pm  view on Meta::CPAN

Returns a list of session IDs of active sessions, useful as arguments to L<Continuity::Mapper>.

=cut

sub sessions {
    return @{ $_[0]->{sesssions} };
}

=head2 $mapper->inspect($session_id, sub { ... } )

Run code in another coroutine's execution context.
The execution context includes the call stack, including all of the data returned by
L<Carp::confess>, L<Padwalker>, L<caller>, and so on.

This creates an L<Continuity::Inspector> instance and sends it over the request queue.
It's just a bit of a shorthand for the same thing.

Returns false if the session_id doesn't exist.

  my $server = Continuity->new();
  my @sessions;

lib/Continuity/RequestHolder.pm  view on Meta::CPAN

    exists $args{$_} or warn "new_requestHolder wants $_ as a parameter"
        for qw/request_queue session_id/;
    $args{request} = undef;
    my $self = { %args };
    bless $self, $class;
    $self->Continuity::debug(2,"  ReqHolder: created, session_id: $args{session_id}");
    bless $self;
}

sub next {
    # called by the user's program from the context of their coroutine
    my $self = shift;

    go_again:

    # If we still have an open request, close it
    if($self->request) {
      $self->Continuity::debug(2,"Closing old req: " . $self->request);
      $self->request->end_request;
    }



( run in 0.289 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )