diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-31 03:07:12 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-31 03:07:12 -0500 |
commit | bc5ef3860cd51aedff32d087ffcebbf80fc026d3 (patch) | |
tree | c82ea7b5196bea061cd652416525bf86bd0313b9 /lib | |
parent | 7ece130cfc351e31e273d14a72ccd8442c0df549 (diff) | |
download | reply-bc5ef3860cd51aedff32d087ffcebbf80fc026d3.tar.gz reply-bc5ef3860cd51aedff32d087ffcebbf80fc026d3.zip |
result cache plugin
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Reply/Plugin/ResultCache.pm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/ResultCache.pm b/lib/Reply/Plugin/ResultCache.pm new file mode 100644 index 0000000..517c539 --- /dev/null +++ b/lib/Reply/Plugin/ResultCache.pm @@ -0,0 +1,41 @@ +package Reply::Plugin::ResultCache; +use strict; +use warnings; + +use base 'Reply::Plugin'; + +sub new { + my $class = shift; + + my $self = $class->SUPER::new(@_); + $self->{results} = []; + + return $self; +} + +sub compile { + my $self = shift; + my ($next, $line, %args) = @_; + + $args{environment} ||= {}; + $args{environment}{'@res'} = $self->{results}; + + $next->($line, %args); +} + +sub execute { + my $self = shift; + my ($next, @args) = @_; + + my @res = $next->(@args); + if (@res == 1) { + push @{ $self->{results} }, $res[0]; + } + elsif (@res > 1) { + push @{ $self->{results} }, \@res; + } + + return @res; +} + +1; |