[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Mac::Dialogs questions



Chris Nandor wrote Date: Sat, 28 Feb 1998 16:18:21 -0500:
>I set the following in your module:
>
>  DESTROY {print $dlg;dispose $dlg}
>  END {print $dlg;dispose $dlg}
>
>When run with END, it worked.  When run with DESTROY, it printed the right
>reference information, but did not dispose.  I don't know why.  Maybe since
>the data is not held in the object, but is a file-wide lexical, the data
>that $dlg refers to had been destroyed before the destructor was called, so
>all that's left is a pointer and no data?  That's all I can think of.

That was what I found also, and it is important to note (as you do) that it
was with the version of GetData in which the MacDialog reference '$dlg'
happened to be global to the package.

END{} behaves differently if $dlg is private (declared 'my' in new()). As
you pointed out in a private e-mail there are dangers in leaving the
MacDialog rerence global, and for those good reasons it should not
generally be done, (and indeed generally is not done).

Brian Matthews wrote on Sat, 28 Feb 1998 16:49:09 -0800:
>Alan Fry writes:
>|I find Chris's method [END block] works but Brian's [DESTROY method]
>|doesn't.
>|Does anyone disagree?
>
>Yes. :-)
>
>I used the little progress dialog example Alan posted a week or so ago
>and added a DESTROY function:
>
>sub DESTROY { $_[0]->close }

Trying this today with 'SimpleStatus.pm' I found Brian's suggestion does
indeed work perfectly. In this module the MacDialog *is* my'ed in new(). If
you add (alternately) these lines at the end:

        sub DESTROY { print "at destroy $_[0]\\n"; $_[0]->close }
or      END { print "at end $_[0]\n"; $_[0]->close }

you find that '$_[0]' is not seen at all in the END{} block. It is however
seen in the DESTROY{} sub-routine and the call to close{} does actually
happen (proved by a 'print' in close{}).

It is odd that DESTROY seems not to work with the 'global $dlg' but perhaps
that is how it is *designed* to be -- it simply doesn't expect to see any
'global' variables, and wouldn't know what to do with one if it did. Is
that it I wonder?

Two other oddments.

1       dispose() does not seem prepared to do any evaluations in its
        argument. It will not recognise:
                dispose $_[0]->{dlg};
        but needs to be spoon-fed a neatly peeled reference:
                $dlg = $_[0]->{dlg}; dispose $dlg;

2       On this machine MacPerl_518/MacOS_8.0/604e the menu-bar equivalent
        to cmd/period (Edit/Stop Script) fails with the error:
        "Callback called exit during global destruction".

        Should not the key-board and menu versions behave identically?

My sincere apologies to Brian for even thinking of suggesting he was wrong
when he knew exactly what should be done all along.

Alan Fry




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch