lib/AI/MicroStructure/Util.pm

filter: Statementstmt 39.5% 19 / 48 Branchbran 12.5% 1 / 8 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 24.7% 26 / 105 CC 18 SCAR 41.5
CC
18
Cov
25%
load_config
94.2
config
72.0
get_cwd
2.1
CRAP 63.6
↑ Summary lib/AI/MicroStructure.pm »
1 package AI::MicroStructure::Util;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Config::Auto;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Env qw/PWD/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub get_cwd {
9 6 ▶ my @CWD; if (!-e ".micro") {
Subroutine get_cwd: called CC=2 SCAR=7.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (not -e '.micro') { } 6 0 6
10 6 push @CWD, $ENV{HOME};
11 } else {
12 0 push @CWD, getcwd();
13 }
14 6 return @CWD;
15 }
16  
17 sub load_config {
18  
19 6 ▶ my @CWD = AI::MicroStructure::Util::get_cwd();
Subroutine load_config: called CC=10 SCAR=45.5
Pod undocumented
20 6 ▶ my $config = Config::Auto::parse(".micro", path => @CWD) || {};
Condition0%0/2
Config::Auto::parse('.micro', 'path', @CWD) || {}
l!l
00
MC/DC0%0/1
Config::Auto::parse('.micro', 'path', @CWD) || {}
Config::Auto::parse('.micro', 'path', @CWD)
Truth table0%0/2
A
A= Config::Auto::parse('.micro', 'path', @CWD)
Aresult
11
00
21 0 ▶ if (-e ".micro" && -e $ENV{HOME}."/.micro") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e ".micro" and -e $ENV{"HOME"} . '/.micro') 0 0 0
Condition0%0/3
-e ".micro" and -e $ENV{"HOME"} . '/.micro'
!ll&&!rl&&r
000
MC/DC0%0/2
-e ".micro" and -e $ENV{"HOME"} . '/.micro'
-e ".micro" -e $ENV{"HOME"} . '/.micro'
Truth table0%0/3
A and B
A= -e ".micro"B= -e $ENV{"HOME"} . '/.micro'
ABresult
0X0
100
111
22 0 my $c = Config::Auto::parse("$ENV{HOME}/.micro");
23 0 ▶ foreach (keys %{$c}) { $config->{$_} ||= $c->{$_}; }
Condition0%0/3
$config->{$_} ||= $c->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{$_} ||= $c->{$_}
$config->{$_} $c->{$_}
Truth table0%0/3
A ||= B
A= $config->{$_}B= $c->{$_}
ABresult
1X1
011
000
24 }
25 0 ▶ if($config->{default}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"default"}) 0 0 0
26 0 shift @CWD;
27 0 push @CWD, $config->{default};
28 0 ▶ if (-e "$CWD[0]/.micro") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$CWD[0]/.micro") 0 0 0
29 0 my $c = Config::Auto::parse("$CWD[0]/.micro");
30 0 ▶ foreach (keys %{$config}) { $c->{$_} ||= $config->{$_}; }
Condition0%0/3
$c->{$_} ||= $config->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->{$_} ||= $config->{$_}
$c->{$_} $config->{$_}
Truth table0%0/3
A ||= B
A= $c->{$_}B= $config->{$_}
ABresult
1X1
011
000
31 0 $config = $c;
32 }
33 }
34 0 my $structdir = "structures";
35 0 my $path = {
36 "structures" => $structdir,
37 "cwd/structures" => "$CWD[0]/$structdir",
38 };
39  
40 0 return { "cwd" => @CWD, "path" => $path, "cfg" => $config };
41  
42 }
43  
44  
45 sub config {
46  
47 0 ▶ my $state = AI::MicroStructure::Util::load_config(); my @CWD = $state->{cwd};
Subroutine config: not called CC=8 SCAR=42.8
Pod undocumented
48 0 ▶ $state->{cfg}->{query} ||= "micro";
Condition0%0/2
$state->{"cfg"}{"query"} ||= "micro"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"query"} ||= "micro"
$state->{"cfg"}{"query"}
Truth table0%0/2
A
A= $state->{"cfg"}{"query"}
Aresult
11
00
49 0 ▶ $state->{cfg}->{tempdir} ||= "/tmp/micro-temp/";
Condition0%0/2
$state->{"cfg"}{"tempdir"} ||= "/tmp/micro-temp/"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"tempdir"} ||= "/tmp/micro-temp/"
$state->{"cfg"}{"tempdir"}
Truth table0%0/2
A
A= $state->{"cfg"}{"tempdir"}
Aresult
11
00
50 0 ▶ $state->{cfg}->{couchdb} ||= "http://localhost:5984/";
Condition0%0/2
$state->{"cfg"}{"couchdb"} ||= "http://localhost:5984/"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"couchdb"} ||= "http://localhost:5984/"
$state->{"cfg"}{"couchdb"}
Truth table0%0/2
A
A= $state->{"cfg"}{"couchdb"}
Aresult
11
00
51 0 ▶ $state->{cfg}->{conceptimg} ||= "http://qunatup.com/tiny/concept2.php";
Condition0%0/2
$state->{"cfg"}{"conceptimg"} ||= "http://qunatup.com/tiny/concept2.php"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"conceptimg"} ||= "http://qunatup.com/tiny/concept2.php"
$state->{"cfg"}{"conceptimg"}
Truth table0%0/2
A
A= $state->{"cfg"}{"conceptimg"}
Aresult
11
00
52 0 ▶ $state->{cfg}->{wikipedia} ||= "http://en.wikipedia.org/wiki/";
Condition0%0/2
$state->{"cfg"}{"wikipedia"} ||= "http://en.wikipedia.org/wiki/"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"wikipedia"} ||= "http://en.wikipedia.org/wiki/"
$state->{"cfg"}{"wikipedia"}
Truth table0%0/2
A
A= $state->{"cfg"}{"wikipedia"}
Aresult
11
00
53 0 ▶ $state->{cfg}->{db} ||= "table";
Condition0%0/2
$state->{"cfg"}{"db"} ||= "table"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"db"} ||= "table"
$state->{"cfg"}{"db"}
Truth table0%0/2
A
A= $state->{"cfg"}{"db"}
Aresult
11
00
54 0 ▶ $state->{cfg}->{out} ||= "json";
Condition0%0/2
$state->{"cfg"}{"out"} ||= "json"
l!l
00
MC/DC0%0/1
$state->{"cfg"}{"out"} ||= "json"
$state->{"cfg"}{"out"}
Truth table0%0/2
A
A= $state->{"cfg"}{"out"}
Aresult
11
00
55 $state->{cfg}->{jsonout} = sprintf("%s/%s/%s-relations",
56 $state->{cwd},
57 $state->{cfg}->{db},
58 0 $state->{cfg}->{query});
59  
60  
61  
62  
63  
64 0 return $state;
65 }
66  
67 6 1;
↑ Summary lib/AI/MicroStructure.pm »