Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How to best pass on the context / wantarray?

by dragonchild (Archbishop)
on Mar 27, 2006 at 01:23 UTC ( #539343=note: print w/ replies, xml ) Need Help??


in reply to How to best pass on the context / wantarray?

DBM::Deep does the following which is inspired by CGI's self_or_default()

sub floober { my $self = shift->_get_self; # Do stuff here with the actual object from tied() as opposed to t +he potentially # blessed item that is tied. }
It's a method because this allows me to overload how to get to the tied method in either DBM::Deep::Array or DBM::Deep::Hash.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?


Comment on Re: How to best pass on the context / wantarray?
Download Code
Re^2: How to best pass on the context / wantarray?
by Corion (Pope) on Mar 27, 2006 at 06:01 UTC

    Something like this was my first idea too, but that doesn't preserve the calling context - wantarray will always be defined in ->_get_self. jdporter's method would solve that problem of course, by inspecting the context one calling level higher.

      I don't think you want the calling context thing. I've been trying to figure out how I would use your proposed API and all it's doing is confusing me. Grandfather said it right.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

      _get_self() doesn't need to have the same context as its caller, it just needs to know the context of its caller. So it is as simple as:

      my $self= shift(@_)->_get_self( wantarray );

      - tye        

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2015-07-06 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls