tags:

views:

65

answers:

1

I got a package called 1.pm in that the constructor is calling a subroutine which is in the same package.

Now, if some other classes say 2.pm is calling the constructor defined in 1.pm, how can I determine if the subroutine is called from 2.pm?

+5  A: 

Use the caller builtin:

$package = caller;

If you want more information you can use:

($package, $filename, $line) = caller;

See perldoc -f caller.

Nathan Fellman
or just `my $package = caller;`.
jrockway
I am using it for Log info. Basically I am tracking all info using Log::Log4perl
Nachikethas
@Nach: Log::Log4perl will automatically track that information for you if you configure it properly; there's no need to take special steps. (See the latest FAQ, on CPAN.)
Ether