summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Reply/Plugin/ResultCache.pm41
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;