NAME

POE::Component::Generic::Object - A POE component that provides non-blocking access to a blocking object.

SYNOPSIS

use POE::Component::Generic;

my $generic = POE::Component::Generic->new( 
                package=>'Builder', 
                factories=>['build'] );

$generic->build( {event=>'created_foo'}, 'foo' );

# Note that this happens in a child process
sub Builder::build {
    my( $package, $arg ) = @_;
    return bless { something=>$arg }, 'Other::Package';
}

# in the event "created_foo"
# Note that this happens in the parent process
sub create_foo {
    my( $resp, $foo ) = @_[ARG0, ARG1];
    die $resp->{error} if $resp->{error}

    # $foo is a proxy object to what Builder::build returned
    my $objID = $foo->object_id;        # Unique ID of the object

    $foo->vibble( {}, @args );          # call a method on the object foo
    $foo->yield( 'vibble', {}, @args ); # same as above   
    $foo->call( 'vibble', {}, @args );  # same as above   

    $generic->vibble( {obj=>$objID}, @args );   # same as above
}

DESCRIPTION

POE::Component::Generic::Object is a proxy object for objects that were created by factory methods in the child process

METHODS

object_id

Returns a object ID for the object. This ID is unique to a given POE::Component::Generic component but might not be unique across POE::Component::Generic components.

session_id

Returns the session ID of the session that handles this object. Currently this corresponse to the parent POE::Component::Generic component, so it's not very useful. Eventually each proxy object will get its own session.

DESTROY

If you let the proxy object go out of scope, the object in the child will be destroyed.

THIS COULD BE SUPRISING.

Especially if you do something like:

my( $resp, $obj ) = @_[ ARG0, ARG1 ];
die $resp->{error} if $resp->{error};
$obj = $obj->object_id;        # bang, no more sub-object.

However, it does allow you to control when the object will be reaped by the child process.

METHOD CALLS

There are 3 ways of calling methods on the object.

All methods need a data hashref to specify the response event. This data hash is discussed in the "INPUT" section.

yield

This method provides an alternative object based means of asynchronisly calling methods on the object. First argument is the method to call, second is the data hashref, following arguments are sent as arguments to the resultant method call.

$poco->yield( open => { event => 'result' }, "localhost" );

call

This method provides an alternative object based means of synchronisly calling methods on the object. First argument is the method to call, second is the data hashref, following arguments are sent as arguments to the resultant method call.

$poco->call( open => { event => 'result' }, "localhost" );

Psuedo-method

All methods of the object can be called, but the first param must be the data hashref as noted below in the "INPUT" section below.

For example:

$poco->open( { event => 'opened' }, "localhost" );

INPUT

Input works the same way as "INPUT" in POE::Component::Generic, except that the obj field defaults to the current object.

OUTPUT

Input works the same way as "OUTPUT" in POE::Component::Generic.

AUTHOR

Philip Gwyn <gwyn-at-cpan.org>

Based on work by David Davis <xantus@cpan.org>

SEE ALSO

POE

RATING

Please rate this module. http://cpanratings.perl.org/rate/?distribution=POE-Component-Generic

BUGS

Probably. Report them here: http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE%3A%3AComponent%3A%3AGeneric

COPYRIGHT AND LICENSE

Copyright 2006-2008, 2011 by Philip Gwyn;

Copyright 2005 by David Davis and Teknikill Software.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.