Skip to content

Commit

Permalink
improved monkey_patch to be able to name generated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 30, 2014
1 parent ed64d42 commit feade2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.35 2014-08-30
- Improved monkey_patch to be able to name generated functions.

5.34 2014-08-29
- Added original_remote_address attribute to Mojo::Transaction.
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -29,6 +29,9 @@ use constant {
PC_INITIAL_N => 128
};

# Will be shipping with Perl 5.22
my $NAME = eval "use Sub::Util; 1" ? \&Sub::Util::set_subname : sub { $_[1] };

# To update HTML entities run this command
# perl examples/entities.pl > lib/Mojo/entities.txt
my %ENTITIES;
Expand Down Expand Up @@ -130,7 +133,7 @@ sub monkey_patch {
my ($class, %patch) = @_;
no strict 'refs';
no warnings 'redefine';
*{"${class}::$_"} = $patch{$_} for keys %patch;
*{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch;
}
# Direct translation of RFC 3492
Expand Down

2 comments on commit feade2e

@29x10
Copy link

@29x10 29x10 commented on feade2e Jan 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you have to name generated functions?

@marcusramberg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better stack traces?

Please sign in to comment.