AcePerl
view release on metacpan or search on metacpan
examples/ace.pl view on Meta::CPAN
#!/usr/bin/perl
# Simple interface to acedb.
# Uses readline for command-line editing if available.
use lib '..','..blib/lib','../blib/arch';
use Ace 1.66;
use Getopt::Long;
use Text::ParseWords;
use strict vars;
use vars qw/@CLASSES @HELP_TOPICS/;
use constant DEBUG => 0;
my ($HOST,$PORT,$PATH,$TCSH,$URL,$AUTOSAVE,$USER,$PASS,@EXEC);
GetOptions('host=s' => \$HOST,
'port=i' => \$PORT,
'path=s' => \$PATH,
'tcsh' => \$TCSH,
'url' => \$URL,
'login:s' => \$USER,
'user:s' => \$USER,
'password:s' => \$PASS,
'save' => \$AUTOSAVE,
'exec=s' => \@EXEC,
) || die <<USAGE;
Usage: $0 [options] [URL]
Interactive Perl client for ACEDB
Options (can be abbreviated):
-host <hostname> Server host (localhost)
-port <port> Server port (200005)
-path <db path> Local database path (no default)
-url <url> Server URL (see below
-login <user> Username
-pass <pass> Password
-tcsh Use T-shell completion mode
-save Save database updates automatically
-exec <command> Run a command and quit
Respects the environment variables \$ACEDB_HOST and \$ACEDB_PORT, if present.
You can edit the command line using the cursor keys and emacs style
key bindings. Use up and down arrows (or ^P, ^N) to access the history.
The tab key completes partial commands. In tcsh mode, the tab key cycles
among the completions, otherwise pressing the tab key a second time lists
all the possibilities.
You may use multiple -exec switches to run a sequence of commands, or
separate multiple commands in a single string by semicolons:
ace.pl -e 'find Author Thierry-Mieg*' -e 'show'
ace.pl -e 'find Author Thierry-Mieg*; show'
Server URLs:
rpcace://hostname:port RPC server
sace://hostname:port Socket server
tace:/path/to/database Local database
/path/to/database Local database
Usernames can be provided as sace://user\@hostname:port
USAGE
;
$HOST ||= $ENV{ACEDB_HOST} || 'localhost';
$PORT ||= $ENV{ACEDB_PORT} || 200005;
$URL = shift if $ARGV[0] =~ /^(rpcace|sace|tace):/;
my $PROMPT = "aceperl> ";
$USER ||= $1 if $URL && $URL=~ m!//(\w+)\@!;
$PASS ||= get_passwd($USER) if $USER;
my $DB = $URL ? Ace->connect(-url=>$URL,-user=>$USER,-pass=>$PASS)
: $PATH ? Ace->connect(-path=>$PATH)
: Ace->connect(-host=>$HOST,-port=>$PORT,-user=>$USER,-pass=>$PASS);
$DB || die "Connection failure: ",Ace->error,"\n";
$DB->auto_save($AUTOSAVE);
if (@EXEC) {
foreach (@EXEC) {
foreach (split (';'))
{ evaluate($_); }
}
exit 0;
}
# read_top_material() if $PATH;
if (@ARGV || !-t STDIN) {
while (<>) {
chomp;
evaluate($_);
}
} elsif (eval "require Term::ReadLine") {
my $term = setup_readline();
while (defined($_ = $term->readline($PROMPT)) ) {
evaluate($_);
}
} else {
$| = 1;
print $PROMPT;
while (<>) {
( run in 0.848 second using v1.01-cache-2.11-cpan-39bf76dae61 )