]>
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->{group
}) {
33 $self->_launch_group($options, @_);
34 } elsif ($options->{single
}) {
35 $self->_launch_single($options, @_);
37 $self->_launch($options, @_);
45 if ($options->{fork}) {
46 for my $file_or_uri (@_) {
50 my $handler = $self->_get_handler($file_or_uri);
51 $handler->($file_or_uri) if $handler;
55 for my $file_or_uri (@_) {
56 my $handler = $self->_get_handler($file_or_uri);
57 $handler->($file_or_uri) if $handler;
66 my ($groups, $handlers) = ({}, {});
67 for my $file_or_uri (@_) {
68 my $handler = $self->_get_handler($file_or_uri);
70 $groups->{"$handler"} //= [];
71 push @{ $groups->{"$handler"} }, $file_or_uri;
72 $handlers->{"$handler"} = $handler;
76 if ($options->{fork}) {
77 for my $group (keys %{ $groups }) {
78 if ($options->{fork}) {
83 $handlers->{$group}->(@{ $groups->{$group} });
87 for my $group (keys %{ $groups }) {
88 $handlers->{$group}->(@{ $groups->{$group} });
97 if ($options->{fork}) {
102 my $handler = $self->_get_handler($_[0]);
103 $handler->(@_) if $handler;
109 my $file_or_uri = $_[0] =~ m
|^file
://(.+)| ? $1 : $_[0];
110 my $mime_or_uri = -e
$file_or_uri ? $self->{mime_query
}->($file_or_uri) : $file_or_uri;
112 for my $target (@{ $self->{targets
} }) {
113 for my $pattern (@{ $target->{patterns
} }) {
114 if ($mime_or_uri =~ /$pattern/) {
115 my $associations = $target->{associations
};
116 for my $context (keys %{ $associations }) {
117 if ($self->{contexts
}->{$context}->()) {
118 return $associations->{$context};
127 App
::Fey-
>new(ref $_[0] ? $_[0] : {})->launch(@_);