Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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 ... }

-stvn


Comment on Re: Moose: possible way to implement trigger in other packages?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://848009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2015-07-07 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls