MooseX::POE::Aliased - A sane alias attribute for your MooseX::POE objects.


MooseX-POE documentation Contained in the MooseX-POE distribution.

Index


Code Index:

NAME

Top

MooseX::POE::Aliased - A sane alias attribute for your MooseX::POE objects.

VERSION

Top

version 0.214

SYNOPSIS

Top

	use MooseX::POE;

    with qw(MooseX::POE::Aliased);

    my $obj = Foo->new( alias => "blah" );

    $obj->alias("arf"); # previous one is removed, new one is set

    $obj->alias(undef); # no alias set

DESCRIPTION

Top

This role provides an alias attribute for your MooseX::POE objects.

The attribute can be set, causing the current alias to be cleared and the new value to be set.

METHODS

Top

alias

The alias to set for the session.

Defaults to the overload::StrVal of the object.

If the value is set at runtime the alias will be updated in the POE::Kernel.

A value of undef inhibits aliasing.

ATTRIBUTES

Top

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


MooseX-POE documentation Contained in the MooseX-POE distribution.

package MooseX::POE::Aliased;
BEGIN {
  $MooseX::POE::Aliased::VERSION = '0.214';
}
# ABSTRACT: A sane alias attribute for your MooseX::POE objects.
use MooseX::POE::Role;

use overload ();

use POE;

has alias => (
    isa => "Maybe[Str]",
    is  => "rw",
    builder     => "_build_alias",
    clearer     => "clear_alias",
    predicate   => "has_alias",
    trigger => sub {
        my ( $self, $alias ) = @_;
        $self->call( _update_alias => $alias );
    }
);

sub BUILD {
    my ($self) = @_;

    $self->call( _update_alias => $self->alias )
      if $self->has_alias;
}

sub _build_alias {
    my $self = shift;
    overload::StrVal($self);
}

event _update_alias => sub {
    my ( $kernel, $self, $alias ) = @_[KERNEL, OBJECT, ARG0];

    # we need to remove the prev alias like this because we don't know the
    # previous value.
    $kernel->alarm_remove_all();

	$kernel->alias_set($alias) if defined $alias;
};

__PACKAGE__;




__END__