AI-MicroStructure
view release on metacpan or search on metacpan
@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($conf{"new"} and $ARGV[0] !~/structures/ and $ARGV[0] =~ m{^([^/]+)/(.*)}s) {
$structure = $1;
$conf{category} = $2;
my $meta = AI::MicroStructure->new( $structure, category => "new" );
$memd->set($argkey,$meta);
p $meta;
exit;
}
if(!$conf{"drop"} && !$conf{"write"}and $ARGV[0] !~/structures/){
# find out the structure name
$structure = shift || $AI::MicroStructure::structure;
if (!length $conf{category} && $structure =~ m{^([^/]+)/(.*)}s) {
$structure = $1;
$conf{category} = $2;
}
AI::MicroStructure->new( $structure, category => "new" )
unless AI::MicroStructure->has_structure( $structure );
# my $module = "AI::MicroStructure::$structure";
my $module = "$absstructdir/$structure.pm";
if(!-f $module){
print "no\n\e[00;33m $module\e[00m";
print "create like\n\e[00;33mmicro $structure new verbose\e[00m";
exit;
}
# load the remote structure if needed
if ( $conf{remote} || $conf{check} || $conf{sources}) {
eval "require '$module';";
die "structure '$structure' is not updatable!\n"
unless $module->has_remotelist();
}
# informative options
print STDERR
"meta, a simple front-end to AI::MicroStructure version $AI::MicroStructure::VERSION\n"
if $conf{version};
print STDERR $main->help if $conf{help};
print map "$_\n", AI::MicroStructure->structures if $conf{structures};
if ( $conf{sources} ) {
my @sources = $module->sources( $conf{category} );
my $var = map "$_\n", @sources;
$memd->set($argkey,$var);
print $var;
exit;
}
exit if $conf{structures} || $conf{version} || $conf{help} || $conf{sources};
my $meta = AI::MicroStructure->new( $structure, category => $conf{category} );
@remote = $module->remote_list( $conf{category} )
if $conf{remote} || $conf{check};
if ( !$conf{remote} ) {
my $count = shift;
$count = 1 unless defined $count;
$count = 0 if $conf{check};
if($all){
@local = $meta->name(0,scalar "");
}else{
@local = $meta->name($count);
}
}
if ( $conf{check} ) {
my %seen;
$seen{$_}++ for @remote;
$seen{$_}-- for @local;
foreach my $key ( sort keys %seen ) {
next unless $seen{$key};
print $seen{$key} > 0 ? "+ $key" : "- $key";
}
}
else {
my $val = sprintf "%s" ,join $sep, @local, @remote;
$memd->set($argkey,$val);
print "$val";
exit;
}
}
END{
( run in 1.522 second using v1.01-cache-2.11-cpan-ceb78f64989 )