line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# /=====================================================================\ # |
2
|
|
|
|
|
|
|
# | NNexus Autolinker | # |
3
|
|
|
|
|
|
|
# | High-level external API | # |
4
|
|
|
|
|
|
|
# |=====================================================================| # |
5
|
|
|
|
|
|
|
# | Part of the Planetary project: http://trac.mathweb.org/planetary | # |
6
|
|
|
|
|
|
|
# | Research software, produced as part of work done by: | # |
7
|
|
|
|
|
|
|
# | the KWARC group at Jacobs University | # |
8
|
|
|
|
|
|
|
# | Copyright (c) 2012 | # |
9
|
|
|
|
|
|
|
# | Released under the MIT License (MIT) | # |
10
|
|
|
|
|
|
|
# |---------------------------------------------------------------------| # |
11
|
|
|
|
|
|
|
# | Adapted from the original NNexus code by | # |
12
|
|
|
|
|
|
|
# | James Gardner and Aaron Krowne | # |
13
|
|
|
|
|
|
|
# |---------------------------------------------------------------------| # |
14
|
|
|
|
|
|
|
# | Deyan Ginev #_# | # |
15
|
|
|
|
|
|
|
# | http://kwarc.info/people/dginev (o o) | # |
16
|
|
|
|
|
|
|
# \=========================================================ooo==U==ooo=/ # |
17
|
|
|
|
|
|
|
package NNexus; |
18
|
2
|
|
|
2
|
|
29512
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
126
|
|
19
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
77
|
|
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
9
|
use Exporter; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
281
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
23
|
|
|
|
|
|
|
our @EXPORT = qw(linkentry indexentry); |
24
|
|
|
|
|
|
|
our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC)); |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
151
|
|
27
|
|
|
|
|
|
|
$VERSION = "2.0.3"; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
515
|
use Mojo::JSON 'j'; |
|
2
|
|
|
|
|
59864
|
|
|
2
|
|
|
|
|
144
|
|
30
|
2
|
|
|
2
|
|
439
|
use NNexus::DB; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
87
|
|
31
|
2
|
|
|
2
|
|
674
|
use NNexus::Job; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
672
|
|
32
|
|
|
|
|
|
|
our %snapshot_credentials = |
33
|
|
|
|
|
|
|
( |
34
|
|
|
|
|
|
|
"dbms" => "SQLite", |
35
|
|
|
|
|
|
|
"dbname" => "$INSTALLDIR/resources/database/snapshot.db", |
36
|
|
|
|
|
|
|
"dbuser" => "nnexus", |
37
|
|
|
|
|
|
|
"dbpass" => "nnexus", |
38
|
|
|
|
|
|
|
"dbhost" => "localhost", |
39
|
|
|
|
|
|
|
) if $INSTALLDIR; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub linkentry { |
42
|
2
|
|
|
2
|
1
|
17
|
my ($body,%options) = @_; |
43
|
2
|
|
|
|
|
6
|
my $db = delete $options{db}; |
44
|
2
|
|
50
|
|
|
12
|
$options{embed} //= 1; |
45
|
2
|
|
50
|
|
|
9
|
$options{format} //= 'html'; |
46
|
2
|
50
|
33
|
|
|
19
|
return $body unless ($db || %snapshot_credentials); |
47
|
2
|
50
|
|
|
|
30
|
$db = NNexus::DB->new(%snapshot_credentials) unless $db; |
48
|
2
|
|
|
|
|
21
|
my $job = NNexus::Job->new(function=>'linkentry',body=>$body,db=>$db,%options); |
49
|
2
|
|
|
|
|
8
|
$job->execute; |
50
|
2
|
|
|
|
|
9
|
my $result = $job->result; |
51
|
2
|
50
|
33
|
|
|
9
|
if ($options{annotation} && ($options{annotation} eq 'json')) {j($result);} |
|
0
|
|
|
|
|
0
|
|
52
|
2
|
|
|
|
|
309
|
return $result; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub indexentry { |
56
|
1
|
|
|
1
|
1
|
7
|
my (%options) = @_; |
57
|
1
|
|
|
|
|
3
|
my $db = delete $options{db}; |
58
|
1
|
50
|
33
|
|
|
12
|
return [] unless ($db || %snapshot_credentials); |
59
|
1
|
50
|
|
|
|
12
|
$db = NNexus::DB->new(%snapshot_credentials) unless $db; |
60
|
1
|
|
|
|
|
7
|
my $job = NNexus::Job->new(function=>'indexentry',db=>$db,%options); |
61
|
1
|
|
|
|
|
5
|
$job->execute; |
62
|
1
|
|
|
|
|
71
|
return $job->result; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |