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 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 ) = @_;
        return grep {
            my $method = $_;
            $self->$method( $class );
        } qw(
            table_for_class
            indexes_for_class
            constraints_for_class
            view_for_class
            insert_for_class
            update_for_class
            delete_for_class
        );
    }

    (This is another case where I wish that aliasing constructs other than foreach made it possible to name the iterator instead of leaving it at “$_ is what’s for dinner, bud.”)

    • (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:
      qw(
                      table_for_class
                      indexes_for_class
                      constraints_for_class
                      view_for_class
                      insert_for_class
                      update_for_class
       
      • 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…