forked from perigrin/moosex-poe
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kill MooseX::Async and migrate to Attribute::Native
- Loading branch information
Showing
5 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package MooseX::POE::Meta::Method::State; | ||
use strict; | ||
use Moose; | ||
extends qw(Moose::Meta::Method); | ||
|
||
no Moose; | ||
1; | ||
__END__ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package MooseX::POE::Meta::Trait; | ||
use Moose::Role; | ||
|
||
use MooseX::POE::Meta::Method::State; | ||
|
||
has events => ( | ||
reader => 'get_events', | ||
traits => ['Array'], | ||
isa => 'ArrayRef', | ||
auto_deref => 1, | ||
lazy_build => 1, | ||
builder => 'default_events', | ||
handles => { 'add_event' => ['push'] }, | ||
); | ||
|
||
sub default_events { | ||
return []; | ||
} | ||
|
||
sub get_state_method_name { | ||
my ( $self, $name ) = @_; | ||
return $name if $self->has_method($name); | ||
return undef; | ||
} | ||
|
||
sub add_state_method { | ||
my ( $self, $name, $method ) = @_; | ||
if ( $self->has_method($name) ) { | ||
my $full_name = $self->get_method($name)->fully_qualified_name; | ||
confess | ||
"Cannot add a state method ($name) if a local method ($full_name) is already present"; | ||
} | ||
|
||
$self->add_event($name); | ||
$self->add_method( $name => $method ); | ||
} | ||
|
||
after add_role => sub { | ||
my ( $self, $role ) = @_; | ||
|
||
if ( $role->isa("MooseX::POE::Meta::Role") ) { | ||
$self->add_event( $role->get_events ); | ||
} | ||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters