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

Hi there, esteemed frequenters of this wonderful community,

Yep, it's brain dead question of the week time again ...

This time I would like to know if it's possible to determine, at runtime, from within a method (whether it be class or instance) whether, or not...

I have read and considered - chaining method calls & Method chain object with easy syntax - (amongst others) but, AFAICT, they don't answer my question.

I have also considered (but not yet too seriously - since it smells less like mastery and more like hackery) whether there's any mileage in using caller & B::Deparse collectively to determine the call context by parsing the calling sub.

As always, any and all suggestions welcomed ...

TIA ,

Update:

The original problem is now solved thanx to the owner of a used module relaxing their intransigence ... that being said, I would still, for the purposes of progressing further down the path of enlightenment, be interested in finding an answer (if there is one).

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re: Determination of chained method call context
by ikegami (Patriarch) on Mar 31, 2009 at 16:08 UTC

    Stop right there. You have a design problem you are trying to brute force using code. Tell us what you are really trying to do.

Re: Determination of chained method call context
by kyle (Abbot) on Mar 31, 2009 at 16:07 UTC

    This isn't a definite solution, but I guess it could help sometimes.

    Long story short, wantarray will always show a scalar context for calls before the end of a chain, but it shows the original context at the end of the chain. If your chain is in a scalar context anyway, that doesn't help at all, but in the other two contexts you can tell you must be at the end.

Re: Determination of chained method call context
by tilly (Archbishop) on Mar 31, 2009 at 19:06 UTC
    Want can give you this.
    use Want qw(want wantref); # Time passes. sub some_method { if (want('REF') and wantref() eq "OBJECT") { # We are in a chained method call } else { # We are not in a chained method call } }
    However I strongly agree with ikegami that the desire to complicate your API this way is a code smell suggesting that you're doing something very wrong somewhere.
      TFT tilly.

      I don't disagree with either yourself or ikegami (as I hinted in my OP) ... but as I said in the update, it's now become purely a matter if interest ... c/w necessity as it previously appeared, to me, to be.

      A user level that continues to overstate my experience :-))