X-Git-Url: https://git.nmode.ca/Fey/blobdiff_plain/2e2b3d1671a5695e0c39c9c1203488ab032c05fd..a36e9479b2f84cc9b4e5b92e304ca2fac8ac8608:/lib/App/Fey.pm diff --git a/lib/App/Fey.pm b/lib/App/Fey.pm index c0778ab..5b9206c 100644 --- a/lib/App/Fey.pm +++ b/lib/App/Fey.pm @@ -29,7 +29,9 @@ sub launch { die "No files or URIs specified.\n" unless @_; - if ($options->{single}) { + if ($options->{group}) { + $self->_launch_group($options, @_); + } elsif ($options->{single}) { $self->_launch_single($options, @_); } else { $self->_launch($options, @_); @@ -57,6 +59,37 @@ sub _launch { } } +sub _launch_group { + my $self = shift; + my $options = shift; + + my ($groups, $handlers) = ({}, {}); + for my $file_or_uri (@_) { + my $handler = $self->_get_handler($file_or_uri); + if ($handler) { + $groups->{"$handler"} //= []; + push @{ $groups->{"$handler"} }, $file_or_uri; + $handlers->{"$handler"} = $handler; + } + } + + if ($options->{fork}) { + for my $group (keys %{ $groups }) { + if ($options->{fork}) { + my $pid = fork; + next if $pid; + } + + $handlers->{$group}->(@{ $groups->{$group} }); + return; + } + } else { + for my $group (keys %{ $groups }) { + $handlers->{$group}->(@{ $groups->{$group} }); + } + } +} + sub _launch_single { my $self = shift; my $options = shift;