in reply to wrapping 'use'?
Yes, use curlies. Pragams (such as use strict and use warnings) are lexically scoped, so they only affect the block in which they are located and child blocks (the blocks which are enclosed by the block in which they are located).
{ no strict 'refs'; ... } # Previous setting resumes after curlies.
The following is a version of your code that disabiles strict refs and warnings for the smallest scope possible:
# Name of the function to wrap. my $sub_name = '...'; # Symbol table entry of the function we want to wrap. my $sub_glob = do { no strict 'refs'; \*$sub_name }; # Reference to the function we want to wrap. my $sub = \&$sub_glob; # The wrapper. my $wrapper = sub { ... $sub->(@_) ... }; # Replace function with its wrapper. { no warnings 'redefine'; *$sub_glob = $wrapper; }
U: Added comments.
|
|---|