From b625025e93c87eab6565ea086e7d9c60245d6bd3 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Mon, 31 Oct 2022 21:20:08 +0000 Subject: Prefer scalar assignment to get caller's first return value Multiple forms of syntax can be used to obtain a package name from `caller`, which emits this as its first return value, and assign that name to a lexical scalar. The following each achieve the same result, but with varying efficiency: * `sub callme { my $package = caller(2); ...}` * `sub callme { my ($package) = caller(2); ...}` * `sub callme { my $package = (caller(2))[0]; ...}` In the first example, `pp_caller` determines only the package name and pushes it to the stack. In the other two examples, the other 10 of `caller`'s return values are calculated and pushed onto the stack, before being discarded. This commit changes non-CPAN-first instances of the latter two forms in core to the first form. Note: There is a special exception to the equivalence described above, when caller is use in list context within the DB package. Such a usage instance in regen/warnings.pl therefore remains unchanged. --- dist/Env/lib/Env.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dist') diff --git a/dist/Env/lib/Env.pm b/dist/Env/lib/Env.pm index eaf30f15a3..991afddc02 100644 --- a/dist/Env/lib/Env.pm +++ b/dist/Env/lib/Env.pm @@ -1,6 +1,6 @@ package Env; -our $VERSION = '1.05'; +our $VERSION = '1.06'; =head1 NAME @@ -75,7 +75,7 @@ Gregor N. Purdy EFE =cut sub import { - my ($callpack) = caller(0); + my $callpack = caller(0); my $pack = shift; my @vars = grep /^[\$\@]?[A-Za-z_]\w*$/, (@_ ? @_ : keys(%ENV)); return unless @vars; -- cgit v1.2.1