Web::Dash::Lens - An experimental Unity Lens object
0.02
use Web::Dash::Lens; use utf8; use Encode qw(encode); sub show_results { my (@results) = @_; foreach my $result (@results) { print "-----------\n"; print encode('utf8', "$result->{name}\n"); print encode('utf8', "$result->{description}\n"); print encode('utf8', "$result->{uri}\n"); } print "=============\n"; } my $lens = Web::Dash::Lens->new(lens_file => '/usr/share/unity/lenses/applications/applications.lens'); ## Synchronous query my @search_results = $lens->search_sync("terminal"); show_results(@search_results); ## Asynchronous query use Future::Q; use Net::DBus::Reactor; $lens->search("terminal")->then(sub { my @search_results = @_; show_results(@search_results); Net::DBus::Reactor->main->shutdown; })->catch(sub { my $e = shift; warn "Error: $e"; Net::DBus::Reactor->main->shutdown; }); Net::DBus::Reactor->main->run();
Web::Dash::Lens is an object that represents a Unity Lens. Note that this module is for using lenses, not for creating your own lenses.
If you use AnyEvent::DBus, do not use *_sync() methods. Instead you have to use asynchronous methods and explicit condition variables.
*_sync()
my $cv = AnyEvent->condvar; $lens->search_hint()->then(sub { $cv->send(@_); }, sub { $cv->croak(shift); }); my $search_hint = $cv->recv;
This is because AnyEvent::DBus replaces the DBus reactor that is not completely compatible with the original Net::DBus::Reactor objects.
The constructor.
Fields in %args are:
%args
lens_file
The file path to .lens file. Usually you can find lens files installed under /usr/share/unity/lenses/.
/usr/share/unity/lenses/
You must either specify lens_file or combination of service_name and object_name.
service_name
object_name
DBus service name of the lens.
In a .lens file, the service name is specified by DBusName field.
DBusName
DBus object name of the lens.
In a .lens file, the object name is specified by DBusPath field.
DBusPath
reactor
Net::DBus::Reactor->main
The Net::DBus::Reactor object. This object is needed for *_sync() methods.
bus_address
The DBus bus address where this module searches for the lens service.
If bus_address is ":session", the session bus will be used. If bus_address is ":system", the system bus will be used. Otherwise, bus_address is passed to Net::DBus->new() method.
Net::DBus->new()
concurrency
The maximum number of asynchronous search queries that the lens handles simultaneously.
If you call searching methods more than this value before any of the requests is complete, the extra requests are queued in the lens and processed later.
Setting concurrency to 0 means there is no concurrency limit.
Makes a search with the $query_string using the $lens. $query_string must be a text string, not a binary (octet) string.
$query_string
$lens
In success, this method returns a list of search results (@results). Each element in @results is a hash-ref containing the following key-value pairs. All the string values are text strings, not binary (octet) strings.
@results
uri
A URI of the result entry. This URI is designed for Unity. Normal applications should refer to dnd_uri below.
dnd_uri
icon_hint
A string that specifies the icon of the result entry.
category_index
The category index for the result entry. You can obtain category information by category() method.
category()
mimetype
MIME type of the result entry.
name
The name of the result entry.
comment
One line description of the result entry.
A URI of the result entry. This URI takes a form that most applications can comprehend. "dnd" stands for "Drag and Drop", I guess.
In failure, this method throws an exception.
See also: https://wiki.ubuntu.com/Unity/Lenses#Schema
The asynchronous version of search_sync() method.
search_sync()
Instead of returning the results, this method returns a Future::Q object that represents the search results obtained in future.
In success, $future will be fulfilled. You can obtain the list of search results by $future->get method.
$future
$future->get
In failure, $future will be rejected. You can obtain the exception by $future->failure method.
$future->failure
Returns the search hint of the $lens. The search hint is a short description of the $lens. $search_hint is a text string, not a binary (or octet) string.
$search_hint
The asynchronous version of search_hint_sync() method.
search_hint_sync()
Instead of returning the results, this method returns a Future::Q object that represents the search hint obtained in future.
When done, $future will be fulfilled. You can obtain the search hint by $future->get method.
Returns a hash-ref describing the category specified by $category_index.
$category_index
$category_index is an integer greater than or equal to zero.
$category_hashref is an hash-ref containing information about the category. It has the following key-value pairs. All the string values are text strings, not binary (octet) strings.
$category_hashref
The name of the category.
A string that specifies the icon of the category.
renderer
A string that specifies how the results in this category should be rendered.
If $category_index is invalid, it throws an exception.
The asynchronous version of category_sync() method.
category_sync()
Instead of returning the category hash-ref, this method returns a Future::Q object.
In success, $future will be fulfilled. You can obtain the category hash-ref by $future->get method.
Returns the DBus service name of the $lens.
Returns the DBus object name of the $lens.
Returns the clone of the $lens.
For how Web::Dash::Lens communicates with a Lens process via DBus, read the source code of Web::Dash::Lens and Web::Dash::DeeModel. I left some comments there.
Toshio Ito <toshioito [at] cpan.org>
<toshioito [at] cpan.org>
To install Web::Dash, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::Dash
CPAN shell
perl -MCPAN -e shell install Web::Dash
For more information on module installation, please visit the detailed CPAN module installation guide.