| 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 <d.ginev@jacobs-university.de> #_# | # | ||||||||||||||||||||||||||||
| 15 | # | http://kwarc.info/people/dginev (o o) | # | ||||||||||||||||||||||||||||
| 16 | # \=========================================================ooo==U==ooo=/ # | ||||||||||||||||||||||||||||
| 17 | package NNexus; | ||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 23 | 2 | our @EXPORT = qw(linkentry indexentry); | |||||||||||||||||||||||||||
| 24 | 2 | our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC)); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 2 | $VERSION = "2.0.3"; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Mojo::JSON 'j'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use NNexus::DB; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use NNexus::Job; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | our %snapshot_credentials = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 2 | ▶ | sub linkentry { | ||||||||||||||||||||||||||
|
Subroutine
linkentry: called CC=8 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | my ($body,%options) = @_; | |||||||||||||||||||||||||||
| 43 | 2 | my $db = delete $options{db}; | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | $options{embed} //= 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{"embed"} //= 1
MC/DC0%0/1
$options{"embed"} //= 1
$options{"embed"}
Truth table50%1/2
A
A= $options{"embed"}
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $options{format} //= 'html'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{"format"} //= "html"
MC/DC0%0/1
$options{"format"} //= "html"
$options{"format"}
Truth table50%1/2
A
A= $options{"format"}
| |||||||||||||||||||||||||||||
| 46 | 2 | ▶ | return $body unless ($db || %snapshot_credentials); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$db or %NNexus::snapshot_credentials
MC/DC0%0/2
$db or %NNexus::snapshot_credentials
$db
%NNexus::snapshot_credentials
Truth table33%1/3
A or B
A= $dbB= %NNexus::snapshot_credentials
| |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | $db = NNexus::DB->new(%snapshot_credentials) unless $db; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 2 | my $job = NNexus::Job->new(function=>'linkentry',body=>$body,db=>$db,%options); | |||||||||||||||||||||||||||
| 49 | 2 | $job->execute; | |||||||||||||||||||||||||||
| 50 | 2 | my $result = $job->result; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($options{annotation} && ($options{annotation} eq 'json')) {j($result);} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options{"annotation"} and $options{"annotation"} eq "json"
MC/DC0%0/2
$options{"annotation"} and $options{"annotation"} eq "json"
$options{"annotation"}
$options{"annotation"} eq "json"
Truth table33%1/3
A and B
A= $options{"annotation"}B= $options{"annotation"} eq "json"
| |||||||||||||||||||||||||||||
| 52 | 2 | return $result; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | sub indexentry { | ||||||||||||||||||||||||||
|
Subroutine
indexentry: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 1 | my (%options) = @_; | |||||||||||||||||||||||||||
| 57 | 1 | my $db = delete $options{db}; | |||||||||||||||||||||||||||
| 58 | 1 | ▶ | return [] unless ($db || %snapshot_credentials); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$db or %NNexus::snapshot_credentials
MC/DC0%0/2
$db or %NNexus::snapshot_credentials
$db
%NNexus::snapshot_credentials
Truth table33%1/3
A or B
A= $dbB= %NNexus::snapshot_credentials
| |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | $db = NNexus::DB->new(%snapshot_credentials) unless $db; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | my $job = NNexus::Job->new(function=>'indexentry',db=>$db,%options); | |||||||||||||||||||||||||||
| 61 | 1 | $job->execute; | |||||||||||||||||||||||||||
| 62 | 1 | return $job->result; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||