SPUG: Tracing back to a calling sub
Jay Scherrer
jay at scherrer.com
Mon Jan 24 14:10:33 PST 2005
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/
More information about the spug-list
mailing list