Apache-Tika-Async
view release on metacpan or search on metacpan
lib/Apache/Tika/Connection/Future.pm view on Meta::CPAN
our $VERSION = '0.11';
has ua => (
is => 'ro',
default => sub {
return Future::HTTP->new()
},
);
sub request( $self, $method, $url, $content, @headers ) {
# Should initialize
$method = uc $method;
my $content_size = length $content;
# 'text/plain' for the language
my %headers= (
"Content-Length" => $content_size,
"Accept" => 'application/json,text/plain',
lib/Apache/Tika/Server.pm view on Meta::CPAN
my( $self )= @_;
$self->java,
@{$self->java_args},
'-jar',
$self->jarfile,
#'--port', $self->port,
'--config', $self->tika_config_temp_file,
@{$self->tika_args},
};
sub spawn_child_win32( $self, @cmd ) {
system(1, @cmd)
}
sub spawn_child_posix( $self, @cmd ) {
require POSIX;
POSIX->import("setsid");
# daemonize
defined(my $pid = fork()) || die "can't fork: $!";
if( $pid ) { # non-zero now means I am the parent
return $pid;
};
# We are the child, close about everything, then exec
chdir("/") || die "can't chdir to /: $!";
(setsid() != -1) || die "Can't start a new session: $!";
open(STDERR, ">&STDOUT") || die "can't dup stdout: $!";
open(STDIN, "< /dev/null") || die "can't read /dev/null: $!";
open(STDOUT, "> /dev/null") || die "can't write to /dev/null: $!";
exec @cmd;
exit 1;
}
sub spawn_child( $self, @cmd ) {
my ($pid);
if( $^O =~ /mswin/i ) {
$pid = $self->spawn_child_win32(@cmd)
} else {
$pid = $self->spawn_child_posix(@cmd)
};
return $pid
}
sub launch( $self ) {
if( !$self->pid ) {
my $cmdline= join " ", $self->cmdline; # well, for Windows...
#warn $cmdline;
my $pid= $self->spawn_child( $self->cmdline )
or croak "Couldn't launch [$cmdline]: $!/$^E";
$self->pid( $pid );
sleep 2; # Java...
};
}
( run in 0.342 second using v1.01-cache-2.11-cpan-65fba6d93b7 )