NAME
Reflex::Role - define a Reflex paramaterized role
VERSION
version 0.071
SYNOPSIS
package Reflex::Role::Streaming;
use Reflex::Role;
use Scalar::Util qw(weaken);
attribute_parameter handle => "handle";
callback_parameter cb_data => qw( on handle data );
callback_parameter cb_error => qw( on handle error );
callback_parameter cb_closed => qw( on handle closed );
method_parameter method_put => qw( put handle _ );
method_parameter method_stop => qw( stop handle _ );
role {
my $p = shift;
my $h = $p->handle();
my $cb_error = $p->cb_error();
with 'Reflex::Role::Collectible';
method_emit_and_stop $cb_error => "error";
with 'Reflex::Role::Reading' => {
handle => $h,
cb_data => $p->cb_data(),
cb_error => $cb_error,
cb_closed => $p->cb_closed(),
};
with 'Reflex::Role::Readable' => {
handle => $h,
active => 1,
};
with 'Reflex::Role::Writing' => {
handle => $h,
cb_error => $cb_error,
method_put => $p->method_put(),
};
with 'Reflex::Role::Writable' => {
handle => $h,
};
# Multiplex a single stop() to the sub-roles.
method $p->method_stop() => sub {
my $self = shift;
$self->stop_handle_readable();
$self->stop_handle_writable();
};
};
1;
DESCRIPTION
Reflex::Role defines a class as a Reflex parameterized role. It adds a few Reflex-specific exports to MooseX::Role::Parameterized.
It will be very helpful to understand the MooseX::Role::Parameterized declarations parameter
, role
and method
before continuing. A basic familiarity with Moose::Role is also assumed.
ROLE PARAMETER DECLARATIONS
Reflex::Role adds a few declarations to MooseX::Role::Parameterized. The role parameter declarations define new parameters for Reflex roles. They're shorthands for MooseX::Role::Parameterized parameter
declarations.
attribute_parameter
Synopsis:
attribute_parameter attribute_name => "default_name";
attribute_parameter
declares a role parameter that will accept an attribute name from the consumer. It also specifies a default attribute name.
attribute_parameter
is a convenience declaration. The synopsis declaration is equivalent to this MooseX::Role::Parameterized syntax
parameter attribute_name => (
isa => 'Str',
default => $default,
);
callback_parameter
Synopsis:
callback_parameter callback_name => qw( prefix attribute_param suffix);
callback_parameter
declares a role parameter that will accept a callback method name. It alsp specifies a default method name, which is the catenation of a prefix, the value of an attribute parameter, and a suffix. A prefix or suffix of "_" will cause that segment of the default to be ignored.
callback_parameter
is a convenience declaration. The synopsis is equivalent to this MooseX::Role::Parameterized syntax:
parameter callback_name => (
isa => 'Str',
lazy => 1,
default => sub {
join(
"_",
grep { defined() and $_ ne "_" }
$prefix, shift()->$attribute_param(), $suffix
)
},
);
method_parameter
Synopsis:
method_parameter method_name => qw( prefix attribute_param suffix );
method_parameter
declares a role parameter that will accept a method name from the consumer. It also specifies a default method name, which is the catenation of a prefix, the value of an attribute parameter, and a suffix. A prefix or suffix of "_" will cause that segment of the default to be ignored.
method_parameter
is a convenience declaration. The synopsis is equivalent to this MooseX::Role::Parameterized syntax:
parameter method_name => (
isa => 'Str',
lazy => 1,
default => sub {
join(
"_",
grep { defined() and $_ ne "_" }
$prefix, shift()->$attribute_param(), $suffix
)
},
);
METHOD DECLARATIONS
Reflex::Role also provides a couple declarations for standard types of methods.
method_emit
Synopsis:
method_emit method_name => "event_name";
method_emit
defines a method that emits an event, via the emit() method provided by Reflex::Role::Reactive. It's common for default Reflex::Role callbacks to emit events, and method_emit
will define such methods.
method_emit
is a convenience declaration. The synopsis is equivalent to this MooseX::Role::Parameterized syntax:
method method_name => sub {
my ($self, $args) = @_;
$self->emit( event => "event_name", args => $args );
};
method_emit_and_stopped
Synopsis:
method_emit_and_stopped method_name => "event_name";
method_emit_and_stopped
defines a method that emits an event and then triggers the object's eventual distruction. It takes the names of the method to define and the event to emit, and it does the rest.
method_emit_and_stopped
is a convenience declaration. The synopsis is equivalent to this MooseX::Role::Parameterized syntax:
method method_name => sub {
my ($self, $args) = @_;
$self->emit( event => "event_name", args => $args );
$self->stopped();
};
TODO
I'm looking for better names for Reflex::Role's exported declarations. Please suggest some.
EXAMPLES
Nearly everything in the Reflex::Role namespace.
SEE ALSO
Reflex Moose MooseX::Role::Parameterized
All the Reflex roles.
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex