Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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]
[karlgoethebier]: funny that they call it Big Dipper in the US. Here this part of Ursa Major is called "Großer Wagen" Big wagon...or car as you like ;-)
[stonecolddevin]: morning all
[shmem]: Big Dipper
[karlgoethebier]: shmem: i remember this album. nice

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2017-11-21 18:12 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (308 votes). Check out past polls.