Class::Method::Cannot? heno-fijw at
Mon Apr 28 18:04:44 BST 2008

Ian Malpass wrote:
> OK, this may be (a) a bad idea, (b) a crack-fuelled idea, (c) already
> done, or (d) all of the above. But, hey, it might be (e) none of the
> above :)
> I want to inherit from a base class, but I want to not inherit methods
> foo() and bar(). I could over-ride these with methods that die(), but
> can() would still see them.
> Question the First: Is there a way to do this sort of thing already?
> Question the Second: If there isn't, how about this approach?
>   * Over-ride can(), which checks to see if the method is in the
> "cannot" list.
>     * If it isn't, call SUPER::can().
>     * If it is, return undef.
>   * Create methods for the "cannot" list that just die with 'Can't
> locate method "$method" via package "$package"'.
> I'm somewhat wary of mucking with can()....
> Question the Third: If that seems like it'd work (and it seems to from
> my simple test) does "Class::Method::Cannot" seem like a reasonable
> thing to put up on CPAN?
> Ian
The way I'd do this is to import all the other subs apart from foo and
bar into your namespace. You could do this on demand with some AUTOLOAD
magic, which will continue to get called each time foo() and bar() are

The last time I did anything like this was Module::Optional, which
allows people to provide dummy methods in their own namespace.


More information about the mailing list