No, caller in the logMessage function itself does something different. Witness:
{ package My::Logger; sub import { my $PACKAGE = caller; no strict 'refs'; *{"$PACKAGE\::log_message"} = sub { my ($message) = @_; print STDERR "$PACKAGE - $message"; }; } } { package My::Utils; My::Logger->import; } { package main; # outputs "My::Utils - Hello", not "main - Hello" My::Utils::log_message("Hello"); }
The log_message function outputs what package it has been installled into, not called from.
While this is rarely useful, it does occasionally have uses. Object::Stash uses something along these lines.
In reply to Re^2: Functions that know which package they've been exported to.
by tobyink
in thread Functions that know which package they've been exported to.
by tobyink
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |