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

FreeBSD Manual Pages

  
 
  

home | help
Thread::Queue::QueueabUser)Contributed Perl DocumenThread::Queue::Queueable(3)

NAME
       Thread::Queue::Queueable	- abstract class for marshalling elements for
       a Thread::Queue::Duplex queue

SYNOPSIS
	       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;
	       }

DESCRIPTION
       Thread::Queue::Queueable	(aka TQQ) provides abstract methods to be
       invoked whenever	an object is enqueued or dequeued, in either the
       request or response direction, on a Thread::Queue::Duplex (TQD) queue.

       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 DBIx::Threaded for an example).

METHODS
       Refer to	the included classdocs for summary and detailed	method
       descriptions.

SEE ALSO
       Thread::Queue::Duplex, threads, threads::shared,	Thread::Queue

AUTHOR,	COPYRIGHT, & LICENSE
       Dean Arnold, Presicient Corp. darnold@presicient.com

       Copyright(C) 2005, Presicient Corp., USA

       Permission is granted to	use this software under	the same terms as Perl
       itself. Refer to	the Perl Artistic License for details.

perl v5.32.0			  2006-03-18	   Thread::Queue::Queueable(3)

NAME | SYNOPSIS | DESCRIPTION | METHODS | SEE ALSO | AUTHOR, COPYRIGHT, & LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Thread::Queue::Queueable&sektion=3&manpath=FreeBSD+12.2-RELEASE+and+Ports>

home | help