]>
iEval git - zeal.git/blob - lib/Zeal/Docset.pm
3143fc8cc1e5c0ed4cab645e1d432478cdd6d915
7 our $VERSION = '0.001001';
9 use parent qw
/Class::Accessor::Fast/;
10 __PACKAGE__
->mk_ro_accessors(qw
/path plist dbh name id family/);
14 use File
::Spec
::Functions qw
/catfile catdir rel2abs/;
18 use File
::Slurp qw
/read_file/;
19 use Mac
::PropertyList
::SAX qw
/parse_plist_file/;
24 my ($class, $path) = @_;
25 $path = realpath
$path;
26 my $plpath = catfile
$path, 'Contents', 'Info.plist';
27 my $dbpath = catfile
$path, 'Contents', 'Resources', 'docSet.dsidx';
28 my $plist = parse_plist_file
($plpath)->as_perl;
29 carp
'This is not a Dash docset' unless $plist->{isDashDocset
};
34 dbh
=> DBI
->connect("dbi:SQLite:dbname=$dbpath", '', ''),
35 name
=> $plist->{CFBundleName
},
36 id
=> $plist->{CFBundleIdentifier
},
37 family
=> $plist->{DocSetPlatformFamily
},
42 my ($self, $docsref) = @_;
44 my %hash = (%$_, docset
=> $self);
45 ($hash{path
}, $hash{anchor
}) = split /#/s, $hash{path
};
46 Zeal
::Document
->new(\
%hash);
51 my ($self, $path) = @_;
52 return HTTP
::Tiny
->new->get($path)->{content
} if $path =~ /^http:/s;
53 my $docroot = catdir
$self->path, 'Contents', 'Resources', 'Documents';
54 $path = rel2abs
$path, $docroot;
55 scalar read_file
$path
59 my ($self, $cond) = @_;
60 my $query = 'SELECT * FROM searchIndex WHERE name LIKE ?';
61 my $res = $self->dbh->selectall_arrayref($query, {Slice
=> {}}, $cond);
62 my @results = $self->_blessdocs($res);
63 wantarray ?
@results : $results[0]
67 my ($self, $cond) = @_;
68 $self->query($cond)->fetch
73 my $query = 'SELECT * FROM searchIndex';
74 my $res = $self->dbh->selectall_arrayref($query, {Slice
=> {}});
75 $self->_blessdocs($res)
85 Zeal::Docset - Class representing a Dash/Zeal docset
90 my $ds = Zeal::Docset->new('/home/mgv/docsets/Perl.docset');
91 say $ds->$path; # /home/mgv/docsets/Perl.docset
94 say $ds->family; # perl
96 # In SQL LIKE, % is .* and _ is .
97 my @matches = $ds->query('perlopen%'); # finds perlopenbsd and perlopentut
98 my $doc = $ds->query('perlsec'); # A Zeal::Document object for perlsec
99 my $html = $ds->get('perls_c'); # HTML documentation of perlsec
100 my @docs = $ds->list; # all documents
104 Dash is an offline API documentation browser. Zeal::Docset is a class
105 representing a Dash/Zeal docset.
111 =item Zeal::Docset->B<new>(I<$path>)
113 Create a Zeal::Docset object from a given docset. I<$path> should be
114 the path to a F<something.docset> directory.
118 The path to the docset folder.
122 A hashref with the contents of Info.plist.
126 A DBI database handle to the docSet.dsidx index.
130 The name of this docset. Equivalent to
131 C<< $ds->plist->{CFBundleName} >>
135 The identifier of this docset. Equivalent to
136 C<< $ds->plist->{CFBundleIdentifier} >>
140 The family this docset belongs to. Dash uses this as the keyword for
141 restricting searches to a particular family of docsets. Equivalent to
142 C<< $ds->plist->{DocSetPlatformFamily} >>
144 =item $ds->B<fetch>(I<$path>)
146 Internal method for fetching the HTML content of a document. I<$path>
147 is either the path to the document relative to C<< $ds->B<path> >> or
150 =item $ds->B<query>(I<$cond>)
152 In list context, return all documents (L<Zeal::Document> instances)
153 matching I<$cond>. In scalar context, return one such document.
154 I<$cond> is a SQL LIKE condition.
156 =item $ds->B<get>(I<$cond>)
158 The HTML content of one document that matches I<$cond>.
159 I<$cond> is a SQL LIKE condition.
161 This method is shorthand for C<< $ds->query(I<$cond>)->fetch >>.
165 The list of all documents (L<Zeal::Document> instances) in this
172 L<Zeal>, L<http://kapeli.com/dash>, L<http://zealdocs.org>
176 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
178 =head1 COPYRIGHT AND LICENSE
180 Copyright (C) 2014-2015 by Marius Gavrilescu
182 This library is free software; you can redistribute it and/or modify
183 it under the same terms as Perl itself, either Perl version 5.20.1 or,
184 at your option, any later version of Perl 5 you may have available.
This page took 0.058339 seconds and 4 git commands to generate.