Fix POD formatting in Zeal.pm
[zeal.git] / lib / Zeal.pm
CommitLineData
c1c9c817
MG
1package Zeal;
2
3use 5.014000;
4use strict;
5use warnings;
6use re '/s';
7
8our $VERSION = '0.000_001';
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");
67 # Add another docset
68 $zeal->add('/home/mgv/somethingelse.docset');
69 # Add a directory containing docsets
70 $zeal->add('/home/mgv/moredocsets/');
71 # Documentation for 'length' in all docsets
72 my $doc = $zeal->query('length');
73 # Documentation for all Test:: perl modules
74 my @docs = $zeal->query('Test::%', 'perl');
75 # Alternative syntax
76 @docs = $zeal->query('perl:Test::%);
77
78=head1 DESCRIPTION
79
80Dash is an offline API documentation browser. Zeal.pm is a module for
81reading and querying Dash documentation sets.
82
83This module queries multiple docsets. If you only have one docset, you
84should use the L<Zeal::Docset> module directly.
85
86Available methods:
87
88=over
89
90=item Zeal->B<new>([I<$path>])
91
92Create a new Zeal object. I<$path> is an optional colon delimited
93string for initializing the object. Each of its components is
94recursively scanned for docsets (and can also be a docset itself). If
0c1fd452 95I<$path> is not provided, the value of I<$ENV{ZEAL_PATH}> (if defined)
c1c9c817
MG
96is used instead.
97
98=item $zeal->B<add>(I<$path>)
99
100Recursively scan a path for docsets, adding them to this object.
101
102=item $zeal->B<sets>([I<$family>])
103
104Return a list of docsets (L<Zeal::Docset> objects) in the given
105family, or in all families if I<$family> is not provided.
106
107=item $zeal->B<query>(I<"$family:$query">)
108
109=item $zeal->B<query>(I<$query>, [I<$family>])
110
111Return a list of documents (L<Zeal::Document> objects) matching a
112query, optionally restricted to a family. In scalar context only one
113such document is returned. I<$query> is a SQL LIKE condition.
114
115=back
116
117=head1 SEE ALSO
118
119L<http://kapeli.com/dash>, L<http://zealdocs.org>
120
121=head1 AUTHOR
122
123Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
124
125=head1 COPYRIGHT AND LICENSE
126
127Copyright (C) 2014 by Marius Gavrilescu
128
129This library is free software; you can redistribute it and/or modify
130it under the same terms as Perl itself, either Perl version 5.20.1 or,
131at your option, any later version of Perl 5 you may have available.
132
133
134=cut
This page took 0.017049 seconds and 4 git commands to generate.