line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zeal::Docset; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14
|
use 5.014000; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001001'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
438
|
use parent qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
248
|
|
|
1
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw/path plist dbh name id family/); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
2747
|
use Carp qw/carp/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
56
|
|
13
|
1
|
|
|
1
|
|
5
|
use Cwd qw/realpath/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
14
|
1
|
|
|
1
|
|
4
|
use File::Spec::Functions qw/catfile catdir rel2abs/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
48
|
|
15
|
1
|
|
|
1
|
|
635
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
39356
|
|
|
1
|
|
|
|
|
40
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1425
|
use DBI; |
|
1
|
|
|
|
|
13361
|
|
|
1
|
|
|
|
|
58
|
|
18
|
1
|
|
|
1
|
|
569
|
use File::Slurp qw/read_file/; |
|
1
|
|
|
|
|
3566
|
|
|
1
|
|
|
|
|
55
|
|
19
|
1
|
|
|
1
|
|
251
|
use Mac::PropertyList::SAX qw/parse_plist_file/; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Zeal::Document; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
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}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
bless { |
32
|
|
|
|
|
|
|
path => $path, |
33
|
|
|
|
|
|
|
plist => $plist, |
34
|
|
|
|
|
|
|
dbh => DBI->connect("dbi:SQLite:dbname=$dbpath", '', ''), |
35
|
|
|
|
|
|
|
name => $plist->{CFBundleName}, |
36
|
|
|
|
|
|
|
id => $plist->{CFBundleIdentifier}, |
37
|
|
|
|
|
|
|
family => $plist->{DocSetPlatformFamily}, |
38
|
|
|
|
|
|
|
}, $class |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _blessdocs { |
42
|
|
|
|
|
|
|
my ($self, $docsref) = @_; |
43
|
|
|
|
|
|
|
map { |
44
|
|
|
|
|
|
|
my %hash = (%$_, docset => $self); |
45
|
|
|
|
|
|
|
($hash{path}, $hash{anchor}) = split /#/s, $hash{path}; |
46
|
|
|
|
|
|
|
Zeal::Document->new(\%hash); |
47
|
|
|
|
|
|
|
} @$docsref; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub fetch { |
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 |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub query { |
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] |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get { |
67
|
|
|
|
|
|
|
my ($self, $cond) = @_; |
68
|
|
|
|
|
|
|
$self->query($cond)->fetch |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub list { |
72
|
|
|
|
|
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
my $query = 'SELECT * FROM searchIndex'; |
74
|
|
|
|
|
|
|
my $res = $self->dbh->selectall_arrayref($query, {Slice => {}}); |
75
|
|
|
|
|
|
|
$self->_blessdocs($res) |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |