Slash Boxes
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.
More | Login | Reply
Loading... please wait.
  • I did a similar refactoring just tonight with far fewer similar method names.

    • With all due respect, I know you're going to get it. I've seen your work (hell, I've worked with you) and I know that you won't blink when you see that. I just worry about the poor maintenance programmer. I'm not too terribly worried as I think that the maintenance programmer who works on this code had better be pretty damned nimble with the Perl chainsaw in the first place, but then, I'm so used to seeing this that I've no idea if it's obscure or not.

  • You're right that different people will draw the line in different places. I think that the original is actually better code, because it's immediately obvious what it does. The refactored version requires a bit of “decoding”.

    The important thing is that you’re thinking about it rather than just refactoring it because you can. (And I guess that this example must be close to your own borderline, or you wouldn't be asking about it.)

  • fifthed: IMO you've taken something very straightforward and made it something to stumble over for no real benefit. And Chris's note about making your method calls ungreppable (or ctaggable) should make this an easy undo.
  • I share your instinct and to refactor this, but your refactored version would strike me as odd immediately upon finding it: why grep { $_ } map { $foo } when that’s exactly the same as grep { $foo }?

    And I think the interpolation is just too clever. It also makes it unnecessarily hard to add or remove method calls that may not follow this naming scheme, should that ever be necessary. So I’d simply say

    sub schema_for_class {
        my $self = shift;
            my ( $class

    • (No, I didn’t intentionally forget to convert the spaces to a tab in my ( $class ) = @_;.)

    • Isn't the return value from your version simply going to be:
      • Ack! Of course. Sigh.

        I guess one could use

        map {
            my $method = $_;
            $self->$method( $class ) || ();
        } @method;

        but I’m not sure how well advised that is…