#!/usr/bin/perl use strict; use Continuity; { package Continuity::Widget; use Moose; use Coro::Continuation; use Data::UUID; has 'uuid' => ( is => 'ro', isa => 'Str', default => sub { Data::UUID->new->create_str } ); has 'output' => (is => 'rw', isa => 'Str', default => ''); has 'cont' => (is => 'rw'); has 'request' => (is => 'rw'); sub process { my ($self) = @_; $self->{cont} ||= continuation { $self->main }; $self->{cont}->(); } sub next { my ($self) = @_; yield; } package Sticky; use Moose; extends 'Continuity::Widget'; has 'contents' => (is => 'rw', isa => 'Str', default => ''); sub main { my ($self) = @_; while(1) { $self->output(q{ Note:
} . $self->contents . q{
}); # Look to see if there is something for specifically us to do do { $self->next } until ($self->request->param('uuid') eq $self->uuid); $self->output(q{ Note:

}); do { $self->next } until ($self->request->param('uuid') eq $self->uuid); $self->contents($self->request->param("contents")); } } } my %stickies; sub main { my $request = shift; while(1) { if (my $action = $request->param('action')) { if ($action eq 'new') { my $sticky = Sticky->new(request => $request); $sticky->process; $stickies{$sticky->uuid} = $sticky; } } $request->print(q{ new sticky
}); # Only process widgets that have data if($request->param('uuid') && defined $stickies{$request->param('uuid')}) { $stickies{$request->param('uuid')}->process; } foreach my $sticky (values %stickies) { $request->print($sticky->output()); } $request->print(q{ }); $request->next; } } Continuity->new(port => 8080)->loop;