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.
  • I agree with you and Dave about the fragile inheritance problem (and wonder if adding hook methods [martinfowler.com] or migrating to a Class::Std [cpan.org]-based object model would solve some of these problems.

    However, one of your suggestions makes a similarly unwarranted assumption, specifically:

    if (UNIVERSAL::can($self->{gallery}, $name) {
        $self->{gallery}->$name(shift);
    };

    What if I want to overload can()? It's a method. Why shouldn't I be able to do that?

    • I'm not sure how to take or answer that question. So I should never use UNIVERSAL::can because you may want to override it? :-)

      Of course, I didn't have to check the method I'm referenceing exists at all. It just seemed like a safety measure. But then again, if you override anything in UNIVERSAL, its effects are your problem, not the modules authors problem right?

      Or, was this comment geared towards the UNIVERSAL::can vs. $object->can debate that flares up from time to time? :-)
      • Yes, it's the great "Why in the world are you explicitly calling the parent implementation of a method on an instance of a known-derived class?" debate. Someday I'm going to write UNIVERSAL::new and write code that calls that directly instead of the actual constructors just to show how stupid a debate it is.

        • Easy killer. :-)

          I'll admit, I'm a tard when it comes to that debate. I've heard mutterings and seen people use can both ways. In an effort to make me less stupid, care to elaborate on the difference between the two in the context of that debate?
          • can() is an object method. There's a default implementation in the UNIVERSAL base class so that classes that don't need to define their own implementations can inherit it.

            Classes for which the default implementation is unsuitable can override it with their own implementations -- and there are good reasons for doing so, such as if you have a proxying or delegation relationship you want to keep transparent, if you autogenerate methods you can't know at compile time and don't necessarily want to install th

            • Using UNIVERSAL::can() as a function is unfair to objects, which might implement their own can method. Using the can method, however, is a real pain, because one can't just say:
              if ($scalar->can("explode")) {
              because the program will die unless $scalar is an object or package name. If it's an unblessed reference or a simple scalar, calling a method throws an exception, so one ends up writing:
              if (ref $scalar and blessed($scalar) and $scalar->can("explode")) {
              which is just a lot of typing, and we know how Perl progammers feel about lots of typing. Maybe Scalar::Util needs to provide able($scalar, $method) that does the above.
              --
              rjbs