lib/NNexus.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 50.0% 6 / 12 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 74.4% 67 / 90 CC 11 SCAR 17.7
CC
11
Cov
79%
linkentry
10.9
indexentry
4.4
BEGIN
1.0
CRAP 5.9
« script/nnexus ↑ Summary lib/NNexus/Index/Mathhub.pm »
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
BranchTrueFalseTotal
if $NNexus::INSTALLDIR 2 0 2
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
l!l
02
MC/DC0%0/1
$options{"embed"} //= 1
$options{"embed"}
Truth table50%1/2
A
A= $options{"embed"}
Aresult
11
00
45 2 ▶ $options{format} //= 'html';
Condition50%1/2
$options{"format"} //= "html"
l!l
20
MC/DC0%0/1
$options{"format"} //= "html"
$options{"format"}
Truth table50%1/2
A
A= $options{"format"}
Aresult
11
00
46 2 ▶ return $body unless ($db || %snapshot_credentials);
Branch: 1 branch
BranchTrueFalseTotal
unless $db or %NNexus::snapshot_credentials 0 2 2
Condition33%1/3
$db or %NNexus::snapshot_credentials
l!l&&r!l&&!r
020
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
ABresult
1X1
011
000
47 2 ▶ $db = NNexus::DB->new(%snapshot_credentials) unless $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $db 2 0 2
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
BranchTrueFalseTotal
if ($options{"annotation"} and $options{"annotation"} eq "json") 0 2 2
Condition33%1/3
$options{"annotation"} and $options{"annotation"} eq "json"
!ll&&!rl&&r
200
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $db or %NNexus::snapshot_credentials 0 1 1
Condition33%1/3
$db or %NNexus::snapshot_credentials
l!l&&r!l&&!r
010
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
ABresult
1X1
011
000
59 1 ▶ $db = NNexus::DB->new(%snapshot_credentials) unless $db;
Branch: 1 branch
BranchTrueFalseTotal
unless $db 1 0 1
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__
« script/nnexus ↑ Summary lib/NNexus/Index/Mathhub.pm »