++ed by:
MILA ABRAXXA

2 PAUSE users
1 non-PAUSE user.

Alex Tokarev

NAME

RPC::ExtDirect::Event - Asynchronous server-to-client events

SYNOPSIS

  use RPC::ExtDirect;
  use RPC::ExtDirect::Event;
 
  sub foo : ExtDirect(pollHandler) {
     my ($class) = @_;
 
     # Do something good, collect results in $good_data
     my $good_data = { ... };
 
     # Do something bad, collect results in $bad_data
     my $bad_data = [ ... ];
 
     # Return the data as a list (not arrayref!)
     return (
                 RPC::ExtDirect::Event->new('good', $good_data),
                 RPC::ExtDirect::Event->new(
                    name => 'bad',
                    data => $bad_data,
                ),
            );
 }

DESCRIPTION

This module implements Event object that is used to send asynchronous events from server to client via periodic polling.

Data can be anything that is serializable to JSON. No checks are made and it is assumed that client side can understand the data format used with Events.

Note that by default JSON will blow up if you try to feed it a blessed object as data payload, and for very good reason: it is not obvious how to serialize a self-contained object. To avoid this, set a global Config option json_options to include allow_blessed flag:

    my $config = RPC::ExtDirect->get_api->config;
    $config->json_options({
        allow_blessed => 1,
    });

METHODS

new

Constructor. Creates a new Event object with event name and some data. Accepts arguments by position as new($name, $data), as well as by name in a hash or hashref:

    my $event1 = RPC::ExtDirect::Event->new( 'foo', 'bar' );
    my $event2 = RPC::ExtDirect::Event->new({
        name => 'foo',
        data => 'bar',
    });
    my $event3 = RPC::ExtDirect::Event->new(
        name => 'foo',
        data => 'bar'
    );

This makes it easier to extend Event objects in a Moose(ish) environment, etc.

run

Instance method. Not intended to be called directly, provided for duck typing compatibility with Exception and Request objects.

result

Instance method. Returns an Event hashref in format required by Ext.Direct client stack. Not intended to be called directly.