How to separate between hash and array in data returned from function (was: Re: [Templates] Fun with arrays)

Paul LeoNerd Evans leonerd@leonerd.org.uk
Sun, 11 Feb 2007 16:22:26 +0000


On Sun, 11 Feb 2007 00:56:17 +0100
Robin Smidsr=C3=B8d <robin@smidsrod.no> wrote:

> One a sidenote, is there some way for an object method to know if it is=20
> being called from a template (instead of from normal perl code)? Is=20
> there some variable that is set that the function has access to which is=
=20
> not set otherwise? Or can I use some kind of function (caller) to=20
> inspect the call stack to figure it out?

Try something like

  if( caller =3D~ m/Template::/ or not wantarray ) {
    return \%hash;
  }
  else {
    return %hash;
  }

--=20
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/