]>
nmode's Git Repositories - Fey/blob - lib/App/Fey.pm
7 our @EXPORT_OK = qw(fey);
11 my ($class, $options) = @_;
12 my $config = do ($ENV{XDG_CONFIG_HOME
} // "$ENV{HOME}/.config") . '/fey/config.pl';
15 mime_query
=> $options->{mime_query
} // $config->{mime_query
} // sub {
16 open my $mime_type, '-|', 'file', '--brief', '--mime-type', $_[0];
19 contexts
=> $options->{contexts
} // $config->{contexts
} // { default => sub { 1 } },
20 targets
=> $options->{targets
} // $config->{targets
} // {}
28 my $options = ref $_[0] ? shift : {};
30 die "No files or URIs specified.\n" unless @_;
32 if ($options->{single
}) {
33 $self->_launch_single($options, @_);
35 $self->_launch($options, @_);
43 if ($options->{fork}) {
44 for my $file_or_uri (@_) {
48 my $handler = $self->_get_handler($file_or_uri);
49 $handler->($file_or_uri) if $handler;
53 for my $file_or_uri (@_) {
54 my $handler = $self->_get_handler($file_or_uri);
55 $handler->($file_or_uri) if $handler;
64 if ($options->{fork}) {
69 my $handler = $self->_get_handler($_[0]);
70 $handler->(@_) if $handler;
76 my $file_or_uri = $_[0] =~ m
|^file
://(.+)| ? $1 : $_[0];
77 my $mime_or_uri = -e
$file_or_uri ? $self->{mime_query
}->($file_or_uri) : $file_or_uri;
79 for my $target (@{ $self->{targets
} }) {
80 for my $pattern (@{ $target->{patterns
} }) {
81 if ($mime_or_uri =~ /$pattern/) {
82 my $associations = $target->{associations
};
83 for my $context (keys %{ $associations }) {
84 if ($self->{contexts
}->{$context}->()) {
85 return $associations->{$context};
94 App
::Fey-
>new(ref $_[0] ? $_[0] : {})->launch(@_);