Changes between Version 5 and Version 6 of WhyPadreNeedsMoose


Ignore:
Timestamp:
Mar 8, 2012, 10:32:31 PM (3 years ago)
Author:
azawawi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WhyPadreNeedsMoose

    v5 v6  
    3333event_key_up fired 
    3434}}} 
     35 
     36Using Moo will also do the trick: 
     37 
     38{{{#!perl 
     39use v5.10; 
     40 
     41package Padre::Document; 
     42 
     43sub new { 
     44  my $class = shift; 
     45  $class = ref $class if ref $class; 
     46  my $self = bless {}, $class; 
     47  $self; 
     48} 
     49 
     501; 
     51 
     52sub event_key_up { say "event_key_up fired"; } 
     53 
     541; 
     55 
     56package NeedsKeyUpEvent; 
     57use Role::Tiny; 
     58requires 'event_key_up'; 
     59before 'event_key_up' => sub { say q{before event_key_up}; }; 
     60after 'event_key_up'  => sub { say q{after event_key_up}; }; 
     611; 
     62 
     63package main; 
     64my $p = Padre::Document->new; 
     65Role::Tiny->apply_roles_to_object($p, qw(NeedsKeyUpEvent)); 
     66$p->event_key_up; 
     67say "-----"; 
     68Padre::Document->new->event_key_up; 
     69}}}