這是我的代碼,已經編輯了「use」語句。他們都按需要工作。POE :: Kernel-> run()需要大約15秒停止/
my $json_data;
sub request {
my ($method, $container, $params, $content_type) = @_;
#get the complete URL, works fine
my $full_url = get_url($method, $container, $params, $content_type);
POE::Component::Client::HTTP->spawn(Alias => 'ua');
# Start a session that will drive the resolver.
# Callbacks are named functions in the "main" package.
POE::Session->create(
inline_states => {
_start => \&_start,
got_response => \&got_response,
}
);
POE::Kernel->run();
return $json_data;
}
sub _start {
my $kernel = $_[KERNEL];
$kernel->post("ua" => "request", "got_response", $full_url);
}
sub got_response {
my ($response_packet) = $_[ARG1];
my $http_response = $response_packet->[0];
my $response_string = $http_response->decoded_content();
$json_data = decode_json($response_string);
print Dumper $json_data;
}
的自卸車在got_response版畫的價值瞬間,但在那之後我有後POE ::內核級>運行執行至少等待15秒return語句。它返回正確的值,但我不能等那麼久。 如果我在子get_reponse dumper語句後添加退出,則不會返回任何值。
任何幫助和建議,將不勝感激。
感謝它幫助。我有3次會議。 –
很高興幫助。乾杯! –