Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Moose: possible way to implement trigger in other packages?

by stvn (Monsignor)
on Jul 04, 2010 at 23:54 UTC ( #848009=note: print w/replies, xml ) Need Help??

in reply to Moose: possible way to implement trigger in other packages?

You can do this using required methods in the role and treating them as delegated "events". This is actually a pretty common technique in the Cocoa framework used by Mac OSX and the iPhone OS. Here is how that might look.

package RolePage; use Moose::Role; has textFont => ( is => 'rw', isa => 'Str', default => 'Courier', trigger => sub { my $self = shift; $self->text_attribute_changed } ); has textSize => ( is => 'rw', isa => 'Int', default => 12, trigger => sub { my $self = shift; $self->text_attribute_changed } ); requires 'text_attribute_changed';
Then in your class you can do:
package CairoPage; use Moose; use Cairo; with 'RolePage'; has cairoFont => ( is => 'bare', isa => 'Cairo::ScaledFont', ); sub text_attribute_changed { # ... do whatever you need to here ... }


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://848009]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-06-18 04:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (107 votes). Check out past polls.