wiki:WhyPadreNeedsMoose

Version 2 (modified by azawawi, 3 years ago) (diff)

--

#!/usr/bin/perl

use v5.10;

package Padre::Document;
use Moose;

sub event_key_up {
    say "event_key_up fired";
}

no Moose;
1;

package NeedsKeyUpEvent;
use Moose::Role;

requires 'event_key_up';

before 'event_key_up' => sub {
    say q{before eats};
}; 

after 'event_key_up' => sub {
    say q{after event_key_up};
}; 

no Moose::Role; 
1;

package main;
my $p = Padre::Document->new(name => 'p');
NeedsKeyUpEvent->meta->apply($p);
$p->event_key_up;
say "-----";
my $q = Padre::Document->new(name => 'q');
$q->event_key_up;