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
|
|
19031
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
19
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
86
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
23
|
|
|
|
|
|
|
our @EXPORT = qw(linkentry indexentry); |
24
|
|
|
|
|
|
|
our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC)); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
3
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
27
|
|
|
|
|
|
|
$VERSION = "2.0.2"; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
460
|
use Mojo::JSON 'j'; |
|
1
|
|
|
|
|
51294
|
|
|
1
|
|
|
|
|
54
|
|
30
|
1
|
|
|
1
|
|
434
|
use NNexus::DB; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
31
|
1
|
|
|
1
|
|
335
|
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__ |