Games-Go-AGA-TDListDB
view release on metacpan or search on metacpan
lib/Games/Go/AGA/TDListDB.pm view on Meta::CPAN
'INSERT OR IGNORE INTO ',
$self->table_name_meta,
' (',
'key, ',
'update_time, ',
'next_tmp_id',
' ) VALUES ( 1, 0, 1 )',
);
}
sub update_time {
my ($self, $new) = @_;
if (@_ > 1) {
$self->sth('update_time')->execute($new);
}
$self->sth('select_time')->execute();
my $time = $self->sth('select_time')->fetchall_arrayref();
$time = $time->[0][0];
return $time || 0;
}
lib/Games/Go/AGA/TDListDB.pm view on Meta::CPAN
sub reap {
my $kid;
my $reaped = 0;
do {
$kid = waitpid(-1, WNOHANG);
$reaped++ if ($kid > 0);
} while $kid > 0;
return $reaped;
}
sub update_from_AGA {
my ($self) = @_;
my $pid;
if ($self->background) {
$pid = fork;
die "fork failed: $!\n" if not defined $pid;
}
if ($pid) {
# parent process
return;
lib/Games/Go/AGA/TDListDB.pm view on Meta::CPAN
my $fname = $self->raw_filename;
my $url = $self->url;
$self->my_print("Starting $fname fetch from $url at ", scalar localtime, "\n") if ($self->verbose);
$self->{ua}->mirror($url, $fname);
$self->my_print("... fetch done at ", scalar localtime, "\n") if ($self->verbose);
$self->update_from_file($fname);
exit if (defined $pid); # exit if this is a spawned child ($pid == 0)
}
sub update_from_file {
my ($self, $fh) = @_;
if (not ref $fh) {
my $fname = $fh;
$fh = undef;
if (not open($fh, '<', $fname)) {
$self->my_print("Error opening $fname for reading: $!\n");
die;
}
}
t/001-TDList.t view on Meta::CPAN
sub fetch_player {
my ($last_name, $first_name) = @_;
$tdlistdb->sth('select_by_name')->execute($last_name, $first_name);
my $found = $tdlistdb->sth('select_by_name')->fetchall_arrayref;
croak("Too many copies of $last_name, $first_name\n") if (@{$found} > 1);
return $found->[0];
}
sub update_from_string {
my ($string) = @_;
my $ref = ref $string ? $string : \$string;
my $fh;
open($fh, '<', $ref)
or croak("Error opening \$string for reading: $!\n");
$tdlistdb->update_from_file($fh);
}
__END__
( run in 0.243 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )