Damian Conway wrote:
>
> Ah, but there's definitely a confusion as to whether it's *meant*
> to be assignable.
> 
> What if I (as the class designer) want to give you read access but not
> write access to an object's name?

I think this misses the mark. We're talking about functions, right?
:lvalue won't save you from the situation you describe:

   $r->func = $x;     # whew! no :lvalue saves us
   $r->func($x);      # but not from this! oh no!

What you have to do is write the function correctly:

   sub func {
       die "assigning to func attempted" if @_;
       $ME->{STATE}->{func};   # return "func" value
   }

Now, if this is what you want, add a :readonly attribute:

   sub func : readonly {
       # auto-die if @_ seen
       $ME->{STATE}->{func};
   }

This saves you from both:

   $r->func = $x;     # whew! having :readonly
   $r->func($x);      # dies for both of these

-Nate

Reply via email to