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.
  • Hmmm, I've been caught out by using accessors like that before. This is a more general code issue, and it's probably fine for your small code, but what happens if you want to store undef in your accessor?

    This is the reason I am leaning more and more towards Class::Accessor and similiar. I note that you'd have to override set() to return $self that way, however.

    -Dom
    • > Hmmm, I've been caught out by using accessors like
      > that before. This is a more general code issue,
      > and it's probably fine for your small code, but
      > what happens if you want to store undef in your
      > accessor?

      Generally I work very hard to make sure I never need to have an undef in any given state :-)

      The object in question will always be in one of two states:
      1. Usable - there is a valid LWP::UserAgent object
      2. Unusable - there is no valid LWP::UserAgent object
      Cases can be made for wanting to store undef however :-)

      I'm pretty big on returning $self from accessors in 'set' mode. That way you can move parameter passing away from the constructor, which makes subclassing later on much easier. If you want set things up at construction time, you can chain your method calls, and still get everything nice and concise in the real estate department without sacrificing flexibility.

      Or maybe I'm a SmallTalk junkie :-)