Already discussed this question on stack
http://stackoverflow.com/questions/43326596/watch-change-of-attribute-inside-perl-class
so now it's closed :)


понедельник, 10 апреля 2017 г., 1:25:07 UTC+3 пользователь Pavel Serikov 
написал:
>
> Hi guys,
>
> Could you please share with me a chunk of code how do you watch attributes 
> change?
> I found good module, Scalar::Watcher 
> <https://metacpan.org/pod/Scalar::Watcher>, but I can't get it work 
> inside a class:
>
> package Cat;
> use Mojo::Base -base;
> use Scalar::Watcher qw(when_modified);
> use feature 'say';
>
> has 'attr1' => 1;
> has 'attr2' => 2;
>
> has 'test' => sub { # "fake" attribute for getting access to $self
>   my $self = shift;
>   when_modified $self->attr1, sub { $self->attr2(3); say "meow" };
> };
>
>
> package main;
> use Data::Dumper;
>
> my $me = Cat->new;
> $me->attr1;
> warn Dumper $me;
> say $me->attr1(3)->attr2; # attr2 is still 2, but must be 3
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to