aboutsummaryrefslogtreecommitdiff
path: root/Plugin/Map.pm
blob: 9ca8cef76e205be4ef45bf6ba6552d0d278c6a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;