RPC::Async::Coderef - wrapper class to ensure that coderefs are unmapped and


RPC-Async documentation Contained in the RPC-Async distribution.

Index


Code Index:

NAME

Top

RPC::Async::Coderef - wrapper class to ensure that coderefs are unmapped and discarded on the client side when garbage collected on the server side

METHODS

Top

new($id)

Constructs a new coderef object.

id()

Return id

set_call($call)

Set callback function

set_destroy($destroy)

Set destroy function

call(@args)

Call callback function with @args

AUTHOR

Top

Troels Liebe Bentsen <tlb@rapanden.dk>, Jonas Jensen <jbj@knef.dk>

COPYRIGHT

Top


RPC-Async documentation Contained in the RPC-Async distribution.
package RPC::Async::Coderef;
use strict;
use warnings;

our $VERSION = '1.05';

use IO::EventMux;

sub new {
    my ($class, $id) = @_;

    my %self = (
        id      => $id,
        call    => undef,
        destroy => undef,
    );

    return bless \%self, (ref $class || $class);
}

sub id {
    my ($self) = @_;
    $self->{id};
}

sub set_call {
    my ($self, $call) = @_;
    $self->{call} = $call;
}

sub set_destroy {
    my ($self, $destroy) = @_;
    $self->{destroy} = $destroy;
}

sub call {
    my ($self, @args) = @_;
    if ($self->{call}) {
        $self->{call}->(@args);
    } else {
        die __PACKAGE__.": callback not set";
    }
}

sub DESTROY {
    my ($self) = @_;
    if ($self->{destroy}) {
        $self->{destroy}->();
        $self->{destroy} = undef;
    }
}

1;

# vim: et sw=4 sts=4 tw=80