Class::Method::Cannot?

Abigail abigail at abigail.be
Mon Apr 28 21:16:32 BST 2008


On Mon, Apr 28, 2008 at 06:04:44PM +0100, heno-fijw at xemaps.com wrote:
> 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
> called.

I think that would fail to work correctly if any of the imported methods
uses SUPER; IIRC, I've written code that (ab)uses this.



Abigail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://london.pm.org/pipermail/london.pm/attachments/20080428/ed323455/attachment.pgp


More information about the london.pm mailing list