Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-07-25 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls