[PATCH] add -p: import Term::ReadKey with 'require'
- From
Thomas Rast <trast@student.ethz.ch>
- Date
- Feb 6, 2009, 19:30 UTC
- Message-ID
- <1233948601-4828-1-git-send-email-trast@student.ethz.ch>
- In-Reply-To
- <20090206140126.GA18364@coredump.intra.peff.net>
eval{use...} is no good because the 'use' is evaluated at compile time, so manually 'require' it. We need to forward declare the functions we use, otherwise Perl raises a compilation error.
Signed-off-by: Thomas Rast <trast@student.ethz.ch> --- Jeff King wrote:
Show 12 quoted lines
> Sorry, I am way behind on git mails, so I didn't catch this sooner. But
> it should be "require Term::ReadKey", as "use" statements are done at
> compile time:
>
> $ perl -e 'eval { use Bogosity } or print "not found\n"'
> Can't locate Bogosity.pm in @INC ...
>
> $ perl -e 'eval { require Bogosity } or print "not found\n"'
> not found
>
> So add--interactive in 'next' is currently broken on non-readkey
> platforms.Damn, sorry.
The code below _seems_ to work. I have to say that beyond the 'require', it's all voodoo to me, so I'd appreciate an extra-careful check.
git-add--interactive.perl | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl index be8ca8e..ec47888 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -40,9 +40,12 @@ my ($diff_new_color) = my $normal_color = $repo->get_color("", "reset"); my $use_readkey = 0; +sub ReadMode; +sub ReadKey; if ($repo->config_bool("interactive.singlekey")) { eval { - use Term::ReadKey; + require Term::ReadKey; + Term::ReadKey->import; $use_readkey = 1; }; }
-- 1.6.1.2.605.ge4655