line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zeal::Docset; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18
|
use 5.014000; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.000_003'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
391
|
use parent qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
265
|
|
|
1
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw/path plist dbh name id family/); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
2655
|
use Carp qw/carp/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
13
|
1
|
|
|
1
|
|
3
|
use Cwd qw/realpath/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
14
|
1
|
|
|
1
|
|
3
|
use File::Spec::Functions qw/catfile catdir rel2abs/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
15
|
1
|
|
|
1
|
|
666
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
40611
|
|
|
1
|
|
|
|
|
40
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1657
|
use DBI; |
|
1
|
|
|
|
|
13820
|
|
|
1
|
|
|
|
|
68
|
|
18
|
1
|
|
|
1
|
|
645
|
use File::Slurp qw/read_file/; |
|
1
|
|
|
|
|
3363
|
|
|
1
|
|
|
|
|
61
|
|
19
|
1
|
|
|
1
|
|
253
|
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__ |