Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to delete a method in a subclass?

by gaal (Parson)
on Dec 17, 2004 at 22:47 UTC ( [id://415802]=note: print w/replies, xml ) Need Help??


in reply to How to delete a method in a subclass?

What do you want to happen if someone calls such a method?

Anyway, yeah -- override the method in the subclass. Have it throw an exception, or do nothing. If you have lots of methods like that (then you should rethink your design, but) you can do something like

sub meth1 { obsoleted } sub meth2 { obsoleted } sub meth3 {} # do nothing, quietly. # [...] sub obsoleted { require Carp; Carp::croak "obsoleted method called"; # exception, with stack tra +ce # or, just complain but go on with the show. Carp::cluck "obsoleted method called"; }

Replies are listed 'Best First'.
Re^2: How to delete a method in a subclass?
by ihb (Deacon) on Dec 21, 2004 at 10:49 UTC

    I'm a fan of keeping the parenthesis for user-defined subroutines, and you give an example of why.

    Your methods will have the string "obsoleted" in them. With warnings enabled a warning will be issued. With strict enabled it'll be a fatal error.

    This is because when the methods are defined there is no &obsoleted subroutine and you don't indicate it's a subroutine in any way.

    Defining &obsoleted above the methods would solve this, but personally I'd just use parenthesis and not worry about where I define subroutines.

    ihb

    See perltoc if you don't know which perldoc to read!
    Read argumentation in its context!

      Yes, that's a good point++.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://415802]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found