Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ...did you call it 'some_method'. has is not sub. It's a nice red herring though, throwing me off completely till I saw rjbs's answer. If it'd been called "some_field", it'd been obvious.

    rjbs has explained what went wrong, but I'm curious why you'd expect it to behave differently. The behaviour is exactly as documented in Moose's section on is => 'rw'|'ro'.

    • Sorry about that. I just hastily threw together an example. But what's the value of allowing me to declare an attribute without an accessor or mutator? I'm sure there's a reason. I just don't see it.

      • There are a few reasons I can imagine, and several I'm fairly sure I'm too afraid to consider. :-)

        One reason would be because one wants to explicitly set the 'reader' and the 'writer'.

        has babelfish => (
            writer => 'schrieb_fish',
            reader => 'lit_fish',
        );

        But that doesn't explain why there is no warning if there is no reader/writer assigned at all. But that could happen because one want to create those sometime during runtime. Wacky, but I can imagine a few motivations to

        • The answer to "why" is simply "because you didn't ask for it". DWIMery is good up until it gets in your way, then it's annoying and difficult to work around. Here is another example (along with perigrin's excellent one) on why you might not want an accessor.

          has foo => ( trigger => sub { my ($self, $value) = @_; $self->bar( $value + 2 ) } );
          has bar => ( is => 'rw', ... );

          Here the side-effectual trigger is used to set the value of bar. Sure, seems kind of esoteric, but it is a valid use case.

          - Stevan