Interesting!
I'm trying to avoid to overbake :) the Proxy, by assigning it to a 'state'
variable or creating a method on-the-fly, in the hope it's treated as a
closure, but no luck so far:
class A {
has $.a;
submethod BUILD {
A.^add_method('proxy', my method proxy(A:) {
say
This might it then:
class A {
has $!a; # $.a if you want to be able to assign with .new
method a() {
Proxy.new(
FETCH => { $!a },
STORE => -> $, $value { $!a = $value * 2 }
)
}
}
my $a = A.new;
$a.a = 77;
dd $a.a; # 154
> On 14 Nov 2017, at
Ah yes, sorry! I'll wait for another answer along with you now.
On Tue, Nov 14, 2017, 7:05 PM Fernando Santagata
wrote:
> Hi yary,
>
> BUILD and TWEAK work during the object creation time, not at the attribute
> assignment time, as far as I know, and I don't have the
Hi yary,
BUILD and TWEAK work during the object creation time, not at the attribute
assignment time, as far as I know, and I don't have the value to assign to
the attribute at the object creation time yet.
On Tue, Nov 14, 2017 at 6:59 PM, yary wrote:
> Fernando, this list
Fernando, this list recently had a discussion on object creation, and all
various ways the attributes are checked and set by the various stages. From
that, what you want is TWEAK, or perhaps BUILD, which let you do things
with the attribute values when the object is created. I leave the research
> On 14 Nov 2017, at 18:06, Fernando Santagata
> wrote:
> I'm converting a program from Perl5/Moose.
> I have several classes, each has some attributes that need to be processed in
> the same way before being passed to other objects.
>
> When I was using Moose, I had
Hello,
I'm converting a program from Perl5/Moose.
I have several classes, each has some attributes that need to be processed
in the same way before being passed to other objects.
When I was using Moose, I had some "around" methods that would
automatically modify the value before delivering it to