Re: "Can't return a temporary from lvalue subroutine..."





Anno Siegel wrote:

I suppose your motivation is that you like the idea of lvalue methods,
but need more control over what gets stored by careless users in your
sensitive objects.  A similar problem exists with objects that expose
(parts of) their interior though overloading a dereference operator,
say %{}.  Like lvalues, it gives you pretty syntax, but leaves your
objects wide open.  I have used tied hashes to correct this (that is,
returned a reference to a tied hash in response to %{ $obj}, and haven't
encountered the particular difficulty you're seeing.  That may be
an alternative approach.

Here be dragons.

There are bugs in Perl. In particular if the reference returned by the %{} overload is the only reference to the tied hash some very nasty things happen very soon. Even if it's not, nasty things seem to happen after a while.

I wrote whole load of in-house classes that used this API technique and then had to labourously go through all our programs to use a direct method-call API rather than the overload-tie API.
.




Relevant Pages

  • Implementing expected core OS functionality
    ... Most documentation and sample code on Windows ... Dolphin provides a wonderful platform for studying the OS API ... might reference the particular API. ...
    (comp.lang.smalltalk.dolphin)
  • Re: Determine if an item in a collection has changed
    ... What people do with API - I don't know. ... >> parent, which by necessity holds a reference to each of its children (via ... >> hold its pointer. ...
    (microsoft.public.vb.general.discussion)
  • Re: Passing python list from C to python
    ... you are importing it from C, but importing it from Python [so that you ... Python/C API reference is 162 pages! ...
    (comp.lang.python)
  • Re: Framebuffer programming
    ... > Please give me the exact link so I may see that the correct URL is ... The new site does not appear to have an API ... >> reference. ... Since my knowledge of the framebuffer is currently ...
    (comp.os.linux.development.apps)
  • Re: [take 3] Use pid in inotify events.
    ... elegant and clean API, which does not break ABI or API. ... Overloading the cookie field is not the way to go. ... extend the API through inotify_init might be--you will have even ...
    (Linux-Kernel)