Class::Method::Cannot?

Ian Malpass ian at indecorous.com
Mon Apr 28 17:41:01 BST 2008


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


More information about the london.pm mailing list