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 those attributes, so
delegating the object to do the needed adjustments.

Stripped to the bare bones, the thing that in Perl6 looks like this:

class A {
  has $!a;

  method a($val?)
  {
    if $val.defined {
      # Modify $val in some way
      $!a = $val;
    } else {
      $!a;
    }
  }
}

my A $a .= new;
# $a.a = 42; # This outputs an error
$a.a(42);
say $a.a;

Any hint how to make it work as an assignment, instead of a method call?
Better yet, is there a way to abstract that behavior in a role?

-- 
Fernando Santagata

Reply via email to