]>
iEval git - zeal.git/blob - lib/Zeal/Docset.pm
7 our $VERSION = '0.000_001';
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) = @_;
43 map { Zeal
::Document
->new(+{%$_, docset
=> $self}) } @
$docsref;
47 my ($self, $path) = @_;
48 return HTTP
::Tiny
->new->get($path)->{content
} if $path =~ /^http:/s;
49 my $docroot = catdir
$self->path, 'Contents', 'Resources', 'Documents';
50 $path = rel2abs
$path, $docroot;
51 scalar read_file
$path
55 my ($self, $cond) = @_;
56 my $query = 'SELECT * FROM searchIndex WHERE name LIKE ?';
57 my $res = $self->dbh->selectall_arrayref($query, {Slice
=> {}}, $cond);
58 my @results = $self->_blessdocs($res);
59 wantarray ?
@results : $results[0]
63 my ($self, $cond) = @_;
64 $self->query($cond)->fetch
69 my $query = 'SELECT * FROM searchIndex';
70 my $res = $self->dbh->selectall_arrayref($query, {Slice
=> {}});
71 $self->_blessdocs($res)
81 Zeal::Docset - Class representing a Dash/Zeal docset
86 my $ds = Zeal::Docset->new('/home/mgv/docsets/Perl.docset');
87 say $ds->$path; # /home/mgv/docsets/Perl.docset
90 say $ds->family; # perl
92 # In SQL LIKE, % is .* and _ is .
93 my @matches = $ds->query('perlopen%'); # finds perlopenbsd and perlopentut
94 my $doc = $ds->query('perlsec'); # A Zeal::Document object for perlsec
95 my $html = $ds->get('perls_c'); # HTML documentation of perlsec
96 my @docs = $ds->list; # all documents
100 Dash is an offline API documentation browser. Zeal::Docset is a class
101 representing a Dash/Zeal docset.
107 =item Zeal::Docset->B<new>(I<$path>)
109 Create a Zeal::Docset object from a given docset. I<$path> should be
110 the path to a F<something.docset> directory.
114 The path to the docset folder.
118 A hashref with the contents of Info.plist.
122 A DBI database handle to the docSet.dsidx index.
126 The name of this docset. Equivalent to
127 C<< $ds->plist->{CFBundleName} >>
131 The identifier of this docset. Equivalent to
132 C<< $ds->plist->{CFBundleIdentifier} >>
136 The family this docset belongs to. Dash uses this as the keyword for
137 restricting searches to a particular family of docsets. Equivalent to
138 C<< $ds->plist->{DocSetPlatformFamily} >>
140 =item $ds->B<fetch>(I<$path>)
142 Internal method for fetching the HTML content of a document. I<$path>
143 is either the path to the document relative to C<< $ds->B<path> >> or
146 =item $ds->B<query>(I<$cond>)
148 In list context, return all documents (L<Zeal::Document> instances)
149 matching I<$cond>. In scalar context, return one such document.
150 I<$cond> is a SQL LIKE condition.
152 =item $ds->B<get>(I<$cond>)
154 The HTML content of one document that matches I<$cond>.
155 I<$cond> is a SQL LIKE condition.
157 This method is shorthand for C<< $ds->query(I<$cond>)->fetch >>.
161 The list of all documents (L<Zeal::Document> instances) in this
168 L<Zeal>, L<http://kapeli.com/dash>, L<http://zealdocs.org>
172 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
174 =head1 COPYRIGHT AND LICENSE
176 Copyright (C) 2014 by Marius Gavrilescu
178 This library is free software; you can redistribute it and/or modify
179 it under the same terms as Perl itself, either Perl version 5.20.1 or,
180 at your option, any later version of Perl 5 you may have available.
This page took 0.077069 seconds and 4 git commands to generate.