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
|
1
|
|
|
1
|
|
19708
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
19
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
102
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
23
|
|
|
|
|
|
|
our @EXPORT = qw(linkentry indexentry); |
24
|
|
|
|
|
|
|
our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC)); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
87
|
|
27
|
|
|
|
|
|
|
$VERSION = "2.0.1"; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
507
|
use Mojo::JSON 'j'; |
|
1
|
|
|
|
|
62605
|
|
|
1
|
|
|
|
|
56
|
|
30
|
1
|
|
|
1
|
|
542
|
use NNexus::DB; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
31
|
1
|
|
|
1
|
|
393
|
use NNexus::Job; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my ($body,%options) = @_; |
43
|
|
|
|
|
|
|
my $db = delete $options{db}; |
44
|
|
|
|
|
|
|
$options{embed} //= 1; |
45
|
|
|
|
|
|
|
$options{format} //= 'html'; |
46
|
|
|
|
|
|
|
return $body unless ($db || %snapshot_credentials); |
47
|
|
|
|
|
|
|
$db = NNexus::DB->new(%snapshot_credentials) unless $db; |
48
|
|
|
|
|
|
|
my $job = NNexus::Job->new(function=>'linkentry',body=>$body,db=>$db,%options); |
49
|
|
|
|
|
|
|
$job->execute; |
50
|
|
|
|
|
|
|
my $result = $job->result; |
51
|
|
|
|
|
|
|
if ($options{annotation} && ($options{annotation} eq 'json')) {j($result);} |
52
|
|
|
|
|
|
|
return $result; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub indexentry { |
56
|
|
|
|
|
|
|
my (%options) = @_; |
57
|
|
|
|
|
|
|
my $db = delete $options{db}; |
58
|
|
|
|
|
|
|
return [] unless ($db || %snapshot_credentials); |
59
|
|
|
|
|
|
|
$db = NNexus::DB->new(%snapshot_credentials) unless $db; |
60
|
|
|
|
|
|
|
my $job = NNexus::Job->new(function=>'indexentry',db=>$db,%options); |
61
|
|
|
|
|
|
|
$job->execute; |
62
|
|
|
|
|
|
|
return $job->result; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |