Melly has asked for the wisdom of the Perl Monks concerning the following question:

Thanks to this forum, I've solved a Tk problem, which basically required $widget->destroy, so...

My question is, how come I couldn't find this? I've check the (ActiveState) docs as best as I can, and I can't find any reference to 'destroy' for Tk widgets. What was I doing wrong?

My only assumption is that 'destroy' is usable against any object from any module, and therefore is not specific to Tk - is this the case?

Tom Melly, tom@tomandlu.co.uk

Replies are listed 'Best First'.
Re: finding stuff in the docs
by Abigail-II (Bishop) on Oct 20, 2003 at 14:52 UTC
    The Tk manuals are messy, and they it's a order of magnitude harder to find your way around them as the general Perl docs are. The 'destroy' methods is not something that's available in just any Perl module, but it is a method that's common to all Tk widgets.

    And methods common to all Tk widgets are described in the Tk::Widget (and not Tk::widget!) manual page.

    Abigail

Re: finding stuff in the docs
by liz (Monsignor) on Oct 20, 2003 at 13:06 UTC
    No, there is no default "destroy" method available for Perl objects.

    However, if the last reference to a blessed object is removed, Perl does look for a method named DESTROY (note uppercase letters, they're required!). And if it can find a DESTROY method, it will execute that. But the author of the module (or one of the modules from which it inherits) will have to have written that method specifically!

    Hope this helps.

    Liz

      The question wasn't about Perl objects, but about Tk widgets. All Tk widgets have an destroy method (lower case). It, unlike DESTROY, does what the name suggests: it destroys the widget, and is an appropriate way of getting rid of widgets.

      Abigail

        My only assumption is that 'destroy' is usable against any object from any module, and therefore is not specific to Tk - is this the case?

        I was referring to the above, incorrect assumption, in case that wasn't clear.

        Liz

Re: finding stuff in the docs
by jdtoronto (Prior) on Oct 20, 2003 at 14:11 UTC
    I think you identified the problem with the docs. It isn't immediately obvious that most Tk widgets inherit methods from the base class. So you need to go and look at Widgets - it gives you the base methods, as well as the particular widget - and in some case the widget is really a mega-widget or combination of widgets thus adding another l;ayer of docs to search.

    jdtoronto

      Pretty much what I thought - I'd have probably found it if I'd been forced to write $mw->Widget::Button(etc.' or something. As it is, and IMHO, 'destroy' should be listed in the man-page for each widget, or there should be a link to the 'widget' man-page from each widget man-page(mentioning that there are additional commands that are generically available).

      I'm tempted to drop a line to the Tk author (it must be at least a couple of months since someone told me to f-off ;)

      Update

      Well, there is a link from each widget to the widget man-page, and it pretty much says what it ought to say: 'The widget also inherits all the methods provided by the generic Tk::Widget class.'

      So, I guess the answer to my original question is 'always check for a "specific-widget methods" section in the docs..'

      Tom Melly, tom@tomandlu.co.uk
Re: finding stuff in the docs
by ptkdb (Monk) on Oct 20, 2003 at 13:38 UTC
    When you installed Tk into your ActiveState installation did you use their PPM package manager, or did you compile and install the source yourself(perl Makefile.PL ; make install)?

    If you used their PPM you should have gotten a Windows help version of the man pages, but not if you did the install 'by hand'.

    At least that's my suspicion.

      Eep. iirc, Tk was included with the original ActiveState install. No, basically I'm not short of documentation on Tk - I just can't find any easy-to-find reference for 'destroy' in it.

      The only place I have found a helpful reference is in UserGuide (accessable via the ActiveState HTML Help) - but to find this I had to do a Windows search on the Tk directory in c:\perl\site\lib\Tk for 'destroy', and then pick through the many offerings to find the one that actually told me what 'destroy' did (rather than just implement it in a coding example without explanation).

      Even in the UserGuide section, it doesn't get its own heading, but gets just one line in the section 'Item creation'.

      The bottom line is that unless you know about 'destroy', it seems a bugger to track down. I dunno - I kind of expected to find some kind of index to available commands for Tk.

      So, I'm afraid I'm still asking, have I missed something, or is tracking down 'destroy' something of a black art?

      Update

      It's in the Widget section as well, with a 'proper' listing.

      Oddly (and I should have mentioned this before as it's part of the reason I was lost), there is no mention of it afaik in the relevant sections of my Perl CD Library (learning, nutshell, programming, advanced, cookbook, etc.) - Oh well...

      Tom Melly, tom@tomandlu.co.uk