NAME

POE::Component::Lingua::Translate - A non-blocking wrapper around Lingua::Translate

SYNOPSIS

use POE;
use POE::Component::Lingua::Translate;

POE::Session->create(
    package_states => [
        main => [ qw(_start translated) ],
    ],
);

$poe_kernel->run();

sub _start {
    my $heap = $_[HEAP];
    $heap->{trans} = POE::Component::Lingua::Translate->new(
        alias => 'translator',
        trans_args => {
            back_end => 'Babelfish',
            src      => 'en',
            dest     => 'de',
        }
    );
    
    $poe_kernel->post(translator => translate => 'this is a sentence');
    return;
}

sub translated {
    my $result = $_[ARG0];
    print $result . "\n";
}

DESCRIPTION

POE::Component::Lingua::Translate is a POE component that provides a non-blocking wrapper around Lingua::Translate. It accepts translate events and emits translated events back.

CONSTRUCTOR

new

Takes two arguments.

'trans_args', a hashref containing arguments that will be passed to Lingua::Translate's constructor. This argument is required.

'alias', an optional alias for the component's session.

METHODS

session_id

Takes no arguments. Returns the POE Session ID of the component.

INPUT

The POE events this component will accept.

translate

Takes one argument, a string to translate. It will be passed to the Lingua::Translate object's translate() method.

shutdown

Takes no arguments, terminates the component.

OUTPUT

The POE events emitted by this component.

translated

ARG0 is the translated text, or undef if the translation failed.

AUTHOR

Hinrik Örn Sigurðsson, hinrik.sig@gmail.com

LICENSE AND COPYRIGHT

Copyright 2008 Hinrik Örn Sigurðsson

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.