in reply to RE: Re: Interfaces
in thread Interfaces

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

Replies are listed 'Best First'.
RE: RE: RE: Re: Interfaces
by ivey (Beadle) on Jun 13, 2000 at 22:44 UTC
    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