To make that even simpler, you could write a subroutine called
Sub that takes a coderef argument and records its file and line number and returns an object that when used as a coderef invokes the coderef, but when used as a string returns the filename/linenumber of creation. How's that for slick? I may even have to code that up for a snippet. Usage would be something like:
my $sub = Sub { my $x = shift; print $x };
$sub->("foo"); # prints foo
print "that was from $sub\n";
Pretty simple to do.
update: see
Track the filename/line number of an anonymous coderef.