in reply to Re: Interfaces
in thread Interfaces

Since you're writing a bunch of subroutines that do the same thing, you can be lazy and just alias them:
sub cant_do_that { my $self = shift; print "Error: Use of undefined Abstract Method by $self.\n"; } use subs qw/methodOne methodTwo/; *methodOne = \&cant_do_that; *methodTwo = \&cant_do_that;

Replies are listed 'Best First'.
RE: RE: Re: Interfaces
by merlyn (Sage) on Jun 07, 2000 at 04:17 UTC
    Thus saith btrott:
    sub cant_do_that { my $self = shift; print "Error: Use of undefined Abstract Method by $self.\n"; } use subs qw/methodOne methodTwo/; *methodOne = \&cant_do_that; *methodTwo = \&cant_do_that;
    I'd simplify the whole lot of that by doing what use subs does directly:
    BEGIN { for my $fakir (qw(methodOne methodTwo)) { *$fakir = sub { die "undef abstract method $fakir used by ".(shift +); } } }
    No fuss, no muss, and you even get a distinguishing mark.

    -- Randal L. Schwartz, Perl hacker

      merlyn:
      BEGIN { for my $fakir (qw(methodOne methodTwo)) { *$fakir = sub { die "undef abstract method $fakir used by ".(shift +); } } }
      causes an error with use strict; (Can't use string ("foo") as a symbol ref) and i needed to add
      no strict 'refs';
      inside the BEGIN:...is there a better way?

      --
      michael d. ivey, ivey@gweezlebur.com