AI-MicroStructure
view release on metacpan or search on metacpan
if($kkey =~ /debug/){
my $NORMAL=`tput sgr0`;
my $REVERSE=`tput smso`;
print "$REVERSE $_ $NORMAL " for @ARGV;
print "\n";
}else{
}
if(defined(my $ret = $memd->get($argkey)) && ($kkey !~ m/(any|structures)/i) && @ARGV){
print "$ret\n";
exit;
#die($ret);
}else{
}
}
init();
if( grep{/\ball\b/} @ARGV ){ $all = 1; cleanArgs("all"); };
our $main = AI::MicroStructure->new();
# check if this is an active memory or initialize it
if($conf{"init"}) {
if (-e ".micro") {
print STDERR "this is already an active memory!\n";
} else {
print `git init && touch .micro && echo .pmc > .gitignore && echo '*~' >> .gitignore && echo '*swp' >> .gitignore && echo .micro >> .gitignore && git add -f .micro .gitignore && git commit -m 'active memory born'`;
}
exit;
} else {
if (!-e ".micro" && !-e $ENV{HOME}."/.micro") {
print STDERR "this directory is not an active memory!\n";
exit;
}
}
my $state = AI::MicroStructure::Util::load_config(); my @CWD=$state->{cwd}; my $config=$state->{cfg};
our $structdir = "structures";
our $absstructdir = "$CWD[0]/$structdir";
if ($conf{"export"}) {
my $cwd = $CWD[0];
my $hash = $main->fitnes();
my $url = sprintf("%s/%s/_all_docs", $config->{couchdb}, $config->{db});
print `cd $cwd && mkdir -p relations && wget -O relations/any.json $url && git add relations/any.json $structdir/*.pm && git commit -m 'active memory release' && git tag $hash`; # FIXME check for errors FIXME also that we commit per structure and...
exit;
}
my (@remote, @local);
# real processing starts here
$\ = $/;
my $sep = $conf{whitespace} ? ' ' : $\;
my $j = $main->structures();
if($j == 0 || $j eq "any"){
print $main->help;
exit(0);
}
sub is_integer {
defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
}
sub cleanArgs{
my ($key) = @_;
my @tmp=();
foreach(@ARGV){
push @tmp,$_ unless($_=~/$key/);}
@ARGV=@tmp;
}
my $structure;
if(defined($ARGV[0]) && $ARGV[0] =~ m/structures/){
@local = grep{!/any/}AI::MicroStructure->new()->structures();
if(defined($ARGV[1]) && is_integer($ARGV[1])){
my $index = rand $#local;
$index = $index-$ARGV[1];
$index = $index?$index:0;
@local = @local[$index+1..$index+$ARGV[1]];
}
my $val = sprintf "%s",join $sep, @local, @remote;
$memd->set($argkey,$val);
print "$val";
exit;
}
if(defined($ARGV[0]) && $ARGV[0] =~ m/structures/){
@local = grep{!/any/}AI::MicroStructure->new()->structures();
if(defined($ARGV[1]) && is_integer($ARGV[1])){
my $index = rand $#local;
$index = $index-$ARGV[1];
$index = $index?$index:0;
( run in 3.542 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )