<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Thread::Queue::Queueable</title>
<link rel="stylesheet" type="text/css" href="../../podstyle.css" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div class="box">
<h1 class="t1">Thread::Queue::Duplex</h1>
<table>
<tr>
<td class="label">Description</td>
<td class="cell">Thread-safe request/response queue with identifiable elements</td>
</tr>
</table>
</div>
<div class="path">
<a href="../../index.html">Thread::Queue::Duplex</a> > Package Manuals >
Thread-Queue-Queueable
</div>
<div>
<a href="../../Thread/Queue/Queueable.html">Classdocs</a>
</div>
<div class="pod">
<!-- INDEX START -->
<h3 id="TOP">Index</h3>
<ul>
<li><a href="#NAME">NAME</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#METHODS">METHODS</a></li>
<li><a href="#SEE_ALSO">SEE ALSO</a></li>
<li><a href="#AUTHOR_COPYRIGHT_amp_LICENSE">AUTHOR, COPYRIGHT, & LICENSE</a></li>
</ul>
<hr />
<!-- INDEX END -->
<h1 id="NAME">NAME <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<p>Thread::Queue::Queueable - abstract class for marshalling elements for a Thread::Queue::Duplex queue</p>
<h1 id="SYNOPSIS">SYNOPSIS <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<pre> use Thread::Queue::Queueable;
use base qw(Thread::Queue::Queueable);
#
# implement onEnqueue method
# (default implementation shown)
#
sub onEnqueue {
my $obj = shift;
#
# capture class name, and create shared
# version of object
#
return $obj->isa('ARRAY') ?
(ref $obj, share([ @$obj ])) :
(ref $obj, share({ %$obj }));
}
#
# implement onDequeue method
# (default implementation shown)
#
sub onDequeue {
my ($class, $obj) = @_;
#
# reconstruct as non-shared
#
$obj = (ref $obj eq 'ARRAY') ? [ @$obj ] : { %$obj };
bless $obj, $class;
return $obj;
}
#
# permit the object to be reconstructed on dequeueing
#
sub onCancel {
my $obj = shift;
return 1;
}
#
# curse (ie, unbless) the object into a shared structure
#
sub curse {
my $obj = shift;
if ($obj->isa('HASH')) {
my %cursed : shared = ();
$cursed{$_} = $obj->{$_}
foreach (keys %$obj);
return \%cursed;
}
my @cursed : shared = ();
$cursed[$_] = $obj->[$_]
foreach (0..$#$obj);
return \@cursed;
}
#
# redeem (ie, rebless) the object into
# the class
#
sub redeem {
my ($class, $obj) = @_;
if (ref $obj eq 'HASH') {
my $redeemed = {};
$redeemed->{$_} = $obj->{$_}
foreach (keys %$obj);
return bless $redeemed, $class;
}
my $redeemed = [];
$redeemed->[$_] = $obj->[$_]
foreach (0..$#$obj);
return bless $redeemed, $class;
}
</pre><h1 id="DESCRIPTION">DESCRIPTION <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<p>Thread::Queue::Queueable (<i>aka TQQ</i>) provides abstract methods to be invoked
whenever an object is enqueued or dequeued, in either the request
or response direction, on a <a href="Duplex.pod.html">Thread::Queue::Duplex</a> (<i>TQD</i>) queue.</p>
<p>The primary purpose is to simplify application logic so that
marshalling/unmarhsalling of objects between threads is performed
automatically. In addition, when subclassed, the application class
can modify or add logic (e.g., notifying a server thread object
to update its reference count when a wrapped object is passed between
threads - see <a href="http://search.cpan.org/perldoc?DBIx%3A%3AThreaded">DBIx::Threaded</a> for an example).</p>
<h1 id="METHODS">METHODS <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<p>Refer to the included classdocs for summary and detailed method descriptions.</p>
<h1 id="SEE_ALSO">SEE ALSO <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<p><a href="Duplex.pod.html">Thread::Queue::Duplex</a>, <a href="http://search.cpan.org/perldoc?threads">threads</a>, <a href="http://search.cpan.org/perldoc?threads%3A%3Ashared">threads::shared</a>, <a href="http://search.cpan.org/perldoc?Thread%3A%3AQueue">Thread::Queue</a></p>
<h1 id="AUTHOR_COPYRIGHT_amp_LICENSE">AUTHOR, COPYRIGHT, & LICENSE <a href="#TOP" class="toplink"><img alt="^" src="../../up.gif" /></a></h1>
<p>Dean Arnold, Presicient Corp. <a href="#darnold_presicient_com">darnold@presicient.com</a></p>
<p>Copyright(C) 2005, Presicient Corp., USA</p>
<p>Permission is granted to use this software under the same terms
as Perl itself. Refer to the Perl Artistic License for details.</p>
</div><div class="footer">generated by <a href="http://search.cpan.org/perldoc?Pod%3A%3AProjectDocs">Pod::ProjectDocs</a></div></body>
</html>