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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2016-10-26 23:52 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (350 votes). Check out past polls.