develooper Front page | perl.moose | Postings from March 2009

MooseX::POE + MooseX::Declare = love?

From:
Mr Guest
Date:
March 15, 2009 18:58
Subject:
MooseX::POE + MooseX::Declare = love?
Message ID:
1237168715.30344.15.camel@luckystar.local.lan
Hello,

This is a working example how it can be achieved. Can it be the right
way while MX::POE is not compatible?

#!/usr/bin/perl -w
use strict;


use MooseX::Declare;
class Foo is mutable extends MooseX::POE::Object {
    BEGIN { Class::MOP::remove_metaclass_by_name(__PACKAGE__); };
    use MooseX::POE qw/event/;
    MooseX::POE->init_meta( for_class => __PACKAGE__ );

    has name => (
        isa     => 'Str',
        is      => 'rw',
        default => sub { 'Foo ' },
    );

    has count => (
        isa     => 'Int',
        is      => 'rw',
        lazy    => 1,
        default => sub { 0 },
    );

    sub START {
        my ($self) = @_;
        $self->yield('increment');
    }

    event increment => sub {
        my ($self) = @_;
        print "Count is now " . $self->count . "\n";
        $self->count( $self->count + 1 );
        $self->yield('increment') unless $self->count > 3;
    };
}


use POE;
Foo->new();
POE::Kernel->run();




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About