Bump version and update Changes
[zeal.git] / lib / Zeal.pm
CommitLineData
c1c9c817
MG
1package Zeal;
2
3use 5.014000;
4use strict;
5use warnings;
6use re '/s';
7
164f653c 8our $VERSION = '0.000_002';
c1c9c817
MG
9
10use File::Spec::Functions qw/catfile/;
11
12use Zeal::Docset;
13use Zeal::Document;
14
15sub new {
16 my ($class, $path) = @_;
17 $path //= $ENV{ZEAL_PATH};
18 my $self = bless {sets => {}}, $class;
19 if ($path) {
20 $self->add($_) for split /:/, $path;
21 }
22 $self
23}
24
25sub add {
26 my ($self, $path) = @_;
27 return unless -d $path;
28 if ($path =~ /[.]docset$/) {
29 my $ds = Zeal::Docset->new($path);
30 $self->{sets}{$ds->family} //= [];
31 push @{$self->{sets}{$ds->family}}, $ds;
32 } else {
33 my $dir;
34 opendir $dir, $path;
35 my @entries = grep { !/^[.]{1,2}$/ } readdir $dir;
36 closedir $dir;
37 $self->add(catfile $path, $_) for @entries
38 }
39}
40
41sub sets {
42 my ($self, $family) = @_;
43 return map { @$_ } values %{$self->{sets}} unless $family;
44 @{$self->{sets}{$family}}
45}
46
47sub query {
48 my ($self, $query, $family) = @_;
49 ($family, $query) = split /:/, $query, 2 if !$family && $query =~ /:/;
50 my @res = map { $_->query($query) } $self->sets($family);
51 wantarray ? @res : $res[0]
52}
53
541;
55__END__
56
57=encoding utf-8
58
59=head1 NAME
60
61Zeal - Read and query Dash/Zeal docsets
62
63=head1 SYNOPSIS
64
65 use Zeal;
66 my $zeal = Zeal->new("/home/mgv/docsets/:/home/mgv/something.docset");
6fbbe902
MG
67 $zeal->add('/home/mgv/somethingelse.docset'); # Add another docset
68 $zeal->add('/home/mgv/moredocsets/'); # Add a directory containing docsets
69
70 my $doc = $zeal->query('length'); # Documentation for 'length' in all docsets
71 my @docs = $zeal->query('Test::%', 'perl'); # Documentation for all Test:: perl modules
72 @docs = $zeal->query('perl:Test::%); # Alternative syntax
c1c9c817
MG
73
74=head1 DESCRIPTION
75
76Dash is an offline API documentation browser. Zeal.pm is a module for
77reading and querying Dash documentation sets.
78
79This module queries multiple docsets. If you only have one docset, you
80should use the L<Zeal::Docset> module directly.
81
82Available methods:
83
84=over
85
86=item Zeal->B<new>([I<$path>])
87
88Create a new Zeal object. I<$path> is an optional colon delimited
89string for initializing the object. Each of its components is
90recursively scanned for docsets (and can also be a docset itself). If
0c1fd452 91I<$path> is not provided, the value of I<$ENV{ZEAL_PATH}> (if defined)
c1c9c817
MG
92is used instead.
93
94=item $zeal->B<add>(I<$path>)
95
96Recursively scan a path for docsets, adding them to this object.
97
98=item $zeal->B<sets>([I<$family>])
99
100Return a list of docsets (L<Zeal::Docset> objects) in the given
101family, or in all families if I<$family> is not provided.
102
103=item $zeal->B<query>(I<"$family:$query">)
104
105=item $zeal->B<query>(I<$query>, [I<$family>])
106
107Return a list of documents (L<Zeal::Document> objects) matching a
108query, optionally restricted to a family. In scalar context only one
109such document is returned. I<$query> is a SQL LIKE condition.
110
111=back
112
113=head1 SEE ALSO
114
115L<http://kapeli.com/dash>, L<http://zealdocs.org>
116
117=head1 AUTHOR
118
119Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
120
121=head1 COPYRIGHT AND LICENSE
122
123Copyright (C) 2014 by Marius Gavrilescu
124
125This library is free software; you can redistribute it and/or modify
126it under the same terms as Perl itself, either Perl version 5.20.1 or,
127at your option, any later version of Perl 5 you may have available.
128
129
130=cut
This page took 0.016366 seconds and 4 git commands to generate.