File Coverage

blib/lib/AI/MicroStructure/Util.pm
Criterion Covered Total %
statement 34 47 72.3
branch 3 8 37.5
condition 8 23 34.7
subroutine 7 7 100.0
pod 0 3 0.0
total 52 88 59.0


line stmt bran cond sub pod time code
1             package AI::MicroStructure::Util;
2              
3 8     8   44 use strict;
  8         13  
  8         238  
4 8     8   44 use Cwd;
  8         16  
  8         563  
5 8     8   7273 use Config::Auto;
  8         50799  
  8         292  
6 8     8   9217 use Env qw/PWD/;
  8         22652  
  8         47  
7              
8             sub get_cwd {
9 8 50   8 0 16 my @CWD; if (!-e ".micro") {
  8         113  
10 8         38 push @CWD, $ENV{HOME}."/data-hub/";
11             } else {
12 0         0 push @CWD, getcwd();
13             }
14 8         30 return @CWD;
15             }
16              
17             sub load_config {
18              
19 8     8 0 32 my @CWD = AI::MicroStructure::Util::get_cwd();
20 8         20 my $config = {};#Config::Auto::parse(".micro", path => @CWD) || {};
21 8 50 33     63 if (-e ".micro" && -e $ENV{HOME}."/.micro") {
22 0         0 my $c = Config::Auto::parse($ENV{HOME}."/.micro");
23 0   0     0 foreach (keys %{$c}) { $config->{$_} ||= $c->{$_}; }
  0         0  
  0         0  
24             }
25 8 50       51 if($config->{default}) {
26 0         0 shift @CWD;
27 0         0 push @CWD, $config->{default};
28 0 0       0 if (-e "$CWD[0]/.micro") {
29 0         0 my $c = Config::Auto::parse("$CWD[0]/.micro");
30 0   0     0 foreach (keys %{$config}) { $c->{$_} ||= $config->{$_}; }
  0         0  
  0         0  
31 0         0 $config = $c;
32             }
33             }
34 8         26 my $structdir = "structures";
35 8         37 my $path = {
36             "structures" => $structdir,
37             "cwd/structures" => "$CWD[0]/$structdir",
38             };
39              
40 8         41 return { "cwd" => @CWD, "path" => $path, "cfg" => $config };
41              
42             }
43              
44              
45             sub config {
46              
47 8     8 0 31 my $state = AI::MicroStructure::Util::load_config(); my @CWD = $state->{cwd};
  8         22  
48 8   50     71 $state->{cfg}->{query} ||= "micro";
49 8   50     50 $state->{cfg}->{tempdir} ||= "/tmp/micro-temp/";
50 8   50     46 $state->{cfg}->{couchdb} ||= "http://localhost:5984/";
51 8   50     55 $state->{cfg}->{conceptimg} ||= "http://qunatup.com/tiny/concept2.php";
52 8   50     43 $state->{cfg}->{wikipedia} ||= "http://en.wikipedia.org/wiki/";
53 8   50     41 $state->{cfg}->{db} ||= "table";
54 8   50     46 $state->{cfg}->{out} ||= "json";
55             $state->{cfg}->{jsonout} = sprintf("%s/%s/",
56             $state->{cwd},
57 8         53 $state->{cfg}->{db});
58              
59              
60              
61              
62              
63 8         29 return $state;
64             }
65             1;