- for my $target (@{ $self->{targets} }) {
- for my $pattern (@{ $target->{patterns} }) {
- if ($mime_or_uri =~ /$pattern/) {
- my $associations = $target->{associations};
- for my $context (keys %{ $associations }) {
- if ($self->{contexts}->{$context}->()) {
- $associations->{$context}->($file_or_uri);
- next ARG;
- }
+ $handlers->{$group}->(@{ $groups->{$group} });
+ return;
+ }
+ } else {
+ for my $group (keys %{ $groups }) {
+ $handlers->{$group}->(@{ $groups->{$group} });
+ }
+ }
+}
+
+sub _launch_single {
+ my $self = shift;
+ my $options = shift;
+
+ if ($options->{fork}) {
+ my $pid = fork;
+ return if $pid;
+ }
+
+ my $handler = $self->_get_handler($options, $_[0]);
+ $handler->(@_) if $handler;
+}
+
+sub _get_handler {
+ my $self = shift;
+ my $options = shift;
+
+ my $file_or_uri = $_[0] =~ m|^file://(.+)| ? $1 : $_[0];
+ my $mime_or_uri = -e $file_or_uri ? $self->{mime_query}->($file_or_uri) : $file_or_uri;
+
+ for my $target (@{ $self->{targets} }) {
+ for my $pattern (@{ $target->{patterns} }) {
+ if ($mime_or_uri =~ /$pattern/) {
+ my $associations = $target->{associations};
+
+ my $context = $options->{context};
+ my $handler = $associations->{$context} if $context;
+ return $handler if defined $handler;
+
+ for my $context (keys %{ $associations }) {
+ if ($self->{contexts}->{$context}->()) {
+ return $associations->{$context};