in reply to Re: Functions that know which package they've been exported to.
in thread Functions that know which package they've been exported to.

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.

Replies are listed 'Best First'.
Re^3: Functions that know which package they've been exported to.
by BrowserUk (Patriarch) on Jan 24, 2012 at 09:48 UTC

    Okay. I can't quite see the use for it, but I do now see the difference.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?