From: Naeem Model Date: Wed, 7 May 2025 23:54:14 +0000 (+0000) Subject: Allow specifying multiple files/URIs X-Git-Url: https://git.nmode.ca/Fey/commitdiff_plain/9c8c23c673e12cc18a0fbd61642c54aecc355d89 Allow specifying multiple files/URIs --- diff --git a/lib/App/Fey.pm b/lib/App/Fey.pm index e17a22a..4400e48 100644 --- a/lib/App/Fey.pm +++ b/lib/App/Fey.pm @@ -21,27 +21,29 @@ sub new { } sub launch { - my ($self, $file_or_uri) = @_; + my $self = shift; - if ($file_or_uri =~ m|^file://(.+)|) { - $file_or_uri = $1; - } + ARG: for my $file_or_uri (@_) { + if ($file_or_uri =~ m|^file://(.+)|) { + $file_or_uri = $1; + } - my ($mime_or_uri, $targets); - if (-e $file_or_uri) { - $mime_or_uri = $self->{mime_query}->($file_or_uri) - } else { - $mime_or_uri = $file_or_uri; - } + my ($mime_or_uri, $targets); + if (-e $file_or_uri) { + $mime_or_uri = $self->{mime_query}->($file_or_uri) + } else { + $mime_or_uri = $file_or_uri; + } - 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); - return; + 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; + } } } } @@ -50,5 +52,5 @@ sub launch { } sub fey { - App::Fey->new($_[1] // {})->launch($_[0] // die 'Error: No file or URI specified.'); + App::Fey->new(ref $_[0] ? shift : {})->launch(@_ ? @_ : die 'Error: No files or URIs specified.'); }