Permalink
Browse files

Cache AUTOLOAD-generated methods for future use

  • Loading branch information...
arc committed Mar 2, 2012
1 parent 09424ad commit 4dabb7276efb457faf1bb7cfe0be765047b288c8
Showing with 14 additions and 2 deletions.
  1. +14 −2 lib/Redis.pm
View
@@ -205,10 +205,22 @@ sub DESTROY { }
our $AUTOLOAD;
sub AUTOLOAD {
- my $self = shift;
-
my $command = $AUTOLOAD;
$command =~ s/.*://;
+
+ my $method = sub { shift->__std_cmd($command, @_) };
+
+ # Save this method for future calls
+ no strict 'refs';
+ *$AUTOLOAD = $method;
+
+ goto $method;
+}
+
+sub __std_cmd {
+ my $self = shift;
+ my $command = shift;
+
$self->__is_valid_command($command);
## Fast path, no reconnect

0 comments on commit 4dabb72

Please sign in to comment.