From 022b4ccf5e80505a237fc7e593d313f41225ac35 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Tue, 15 Feb 2011 12:20:18 +1100 Subject: [PATCH] Only encode @ARGV once. Fixes #176 --- Changes | 12 ++++++++---- lib/perl5i/2.pm | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 3a208d8..0fe72d4 100644 --- a/Changes +++ b/Changes @@ -3,14 +3,18 @@ * Added capture(), from Capture::Tiny, to capture output to STDOUT and STDERR [github 178] - Windows Fixes - * Fix t/center.t (Myf White) - * Fix t/command_line_wrapper.t (Myf White) - New Docs * Added perl5ifaq entries for capturing output from a command using capture() + Bug Fixes + * perl5i will no longer double encode @ARGV if it's loaded multiple times. + [github 176] + + Windows Fixes + * Fix t/center.t (Myf White) + * Fix t/command_line_wrapper.t (Myf White) + Misc * The dependency on true.pm will no longer confuse some YAML parsers. diff --git a/lib/perl5i/2.pm b/lib/perl5i/2.pm index 08c5114..e9ad15a 100644 --- a/lib/perl5i/2.pm +++ b/lib/perl5i/2.pm @@ -84,7 +84,8 @@ sub import { (\&capture)->alias($caller, "capture"); # utf8ify @ARGV - $_ = Encode::decode('utf8', $_) for @ARGV; + state $have_encoded_argv = 0; + _encode_argv() unless $have_encoded_argv++; # Current lexically active major version of perl5i. $^H{perl5i} = 2; @@ -187,3 +188,8 @@ sub capture(&;@) { my $func = $captures->{$opts}; return $func->($code); } + +sub _encode_argv { + $_ = Encode::decode('utf8', $_) for @ARGV; + return; +}