| 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
| |||||||||||||||||||||||||||||
| 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) || {}
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)
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (-e ".micro" && -e $ENV{HOME}."/.micro") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e ".micro" and -e $ENV{"HOME"} . '/.micro'
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'
| |||||||||||||||||||||||||||||
| 22 | 0 | my $c = Config::Auto::parse("$ENV{HOME}/.micro"); | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | foreach (keys %{$c}) { $config->{$_} ||= $c->{$_}; } | ||||||||||||||||||||||||||
|
Condition0%0/3
$config->{$_} ||= $c->{$_}
MC/DC0%0/2
$config->{$_} ||= $c->{$_}
$config->{$_}
$c->{$_}
Truth table0%0/3
A ||= B
A= $config->{$_}B= $c->{$_}
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if($config->{default}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | shift @CWD; | |||||||||||||||||||||||||||
| 27 | 0 | push @CWD, $config->{default}; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (-e "$CWD[0]/.micro") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | my $c = Config::Auto::parse("$CWD[0]/.micro"); | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | foreach (keys %{$config}) { $c->{$_} ||= $config->{$_}; } | ||||||||||||||||||||||||||
|
Condition0%0/3
$c->{$_} ||= $config->{$_}
MC/DC0%0/2
$c->{$_} ||= $config->{$_}
$c->{$_}
$config->{$_}
Truth table0%0/3
A ||= B
A= $c->{$_}B= $config->{$_}
| |||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$state->{"cfg"}{"query"} ||= "micro"
$state->{"cfg"}{"query"}
Truth table0%0/2
A
A= $state->{"cfg"}{"query"}
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $state->{cfg}->{tempdir} ||= "/tmp/micro-temp/"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"tempdir"} ||= "/tmp/micro-temp/"
MC/DC0%0/1
$state->{"cfg"}{"tempdir"} ||= "/tmp/micro-temp/"
$state->{"cfg"}{"tempdir"}
Truth table0%0/2
A
A= $state->{"cfg"}{"tempdir"}
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $state->{cfg}->{couchdb} ||= "http://localhost:5984/"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"couchdb"} ||= "http://localhost:5984/"
MC/DC0%0/1
$state->{"cfg"}{"couchdb"} ||= "http://localhost:5984/"
$state->{"cfg"}{"couchdb"}
Truth table0%0/2
A
A= $state->{"cfg"}{"couchdb"}
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $state->{cfg}->{conceptimg} ||= "http://qunatup.com/tiny/concept2.php"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"conceptimg"} ||= "http://qunatup.com/tiny/concept2.php"
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"}
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $state->{cfg}->{wikipedia} ||= "http://en.wikipedia.org/wiki/"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"wikipedia"} ||= "http://en.wikipedia.org/wiki/"
MC/DC0%0/1
$state->{"cfg"}{"wikipedia"} ||= "http://en.wikipedia.org/wiki/"
$state->{"cfg"}{"wikipedia"}
Truth table0%0/2
A
A= $state->{"cfg"}{"wikipedia"}
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $state->{cfg}->{db} ||= "table"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"db"} ||= "table"
MC/DC0%0/1
$state->{"cfg"}{"db"} ||= "table"
$state->{"cfg"}{"db"}
Truth table0%0/2
A
A= $state->{"cfg"}{"db"}
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $state->{cfg}->{out} ||= "json"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$state->{"cfg"}{"out"} ||= "json"
MC/DC0%0/1
$state->{"cfg"}{"out"} ||= "json"
$state->{"cfg"}{"out"}
Truth table0%0/2
A
A= $state->{"cfg"}{"out"}
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||