SPUG: Tracing back to a calling sub
Peter Darley
pdarley at kinesis-cem.com
Mon Jan 24 14:38:43 PST 2005
Jay,
Wouldn't $myinstance have to be blessed as an object to do that?
Thanks,
Peter Darley
-----Original Message-----
From: spug-list-bounces at pm.org [mailto:spug-list-bounces at pm.org]On
Behalf Of Jay Scherrer
Sent: Monday, January 24, 2005 2:11 PM
To: spug-list at pm.org
Subject: Re: SPUG: Tracing back to a calling sub
Couldn't you use a class shift?
I know from using Perl::Tk you would call mySub like this:
$myinstance->mysub($arg1, $arg2);
When this gets passed the -> acts like a comma seperated list.
And from the pakage::MySub you would get this:
sub MySub {
my $this = shift;
my (%Args) = @_;
if (! $Args{Query}) {die "A null querry was passed to MySub from
$this";
}
Jay Scherrer
On Monday 24 January 2005 08:34 am, Peter Darley wrote:
> Folks,
> I'm trying to figure out if there's a way for a sub to find out
> what sub called it? The situation that I'm in is that I have a lot
> of generic subs, such as one that takes a database query string and
> returns a hash of what was loaded from the database. When it
> fails, I just get an error from the sub, but it's almost always a
> error in how I called the sub that caused problems, and it can be
> hard to go back through my program and find which sub called this
> sub incorrectly.
> So, basically what I want to be able to do is have something like:
>
> sub MySub
> {
> my (%Args) = @_;
> # Args: Query = The query to run the Lookup on
>
> if (! $Args{Query}) {die "A null querry was passed to MySub from
> $Calling_Sub!"}
>
> ...
> }
>
> And it would come up with something like
> "A null querry was passed to MySub from LookupUserInfo()!"
>
> Thanks,
> Peter Darley
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
> WEB PAGE: http://seattleperl.org/
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
WEB PAGE: http://seattleperl.org/
More information about the spug-list
mailing list