diff options
author | David Phillips <david@sighup.nz> | 2018-04-10 15:06:10 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-04-10 15:06:29 +1200 |
commit | bb1808b1ef92af9a14a073f2e14973ac132b7e7e (patch) | |
tree | 5cf3fb9174e07242ed258ae327d3506df1a5355c /plugin/map.pm | |
parent | 5aad7b27d5145d4f459ab36d3ffe4a576d3f4ea6 (diff) | |
download | idalius-bb1808b1ef92af9a14a073f2e14973ac132b7e7e.tar.xz |
Add command modules, map command
Diffstat (limited to 'plugin/map.pm')
-rw-r--r-- | plugin/map.pm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/plugin/map.pm b/plugin/map.pm new file mode 100644 index 0000000..f8cb256 --- /dev/null +++ b/plugin/map.pm @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +package plugin::map; + +use strict; +use warnings; + +my %config; +my $run_command; + + +sub configure { + my $self = shift; + my $cmdref = shift; + my $cref = shift; + %config = %$cref; + $run_command = shift; + + $cmdref->("map", sub { $self->map(@_); } ); + + return $self; +} + +sub map { + my ($self, $logger, $who, $where, $rest, @arguments) = @_; + my ($command, $subjects) = ($rest =~ /^(.+?)\s+(.*)$/); + + return "[]" unless $subjects; + + my @array = map { $run_command->("$command $_", $who, $where) } (split /,/, $subjects); + + return "[" . (join ", ", @array). "]"; +} +1; |