/[Frey]/trunk/lib/Frey/Translate.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Frey/Translate.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 291 - (hide annotations)
Wed Nov 5 08:21:02 2008 UTC (15 years, 6 months ago) by dpavlin
File size: 724 byte(s)
 r3133@llin (orig r257):  dpavlin | 2008-11-04 20:56:08 +0100
 added Frey::Translate

1 dpavlin 291 package Frey::Translate;
2     use Moose;
3     use REST::Google::Translate;
4    
5     =head1 DESCRIPTION
6    
7     translate text using L<REST::Google::Translate>
8    
9     =cut
10    
11     has 'text' => (
12     is => 'rw',
13     isa => 'Str',
14     required => 1,
15     );
16    
17     has 'from' => (
18     is => 'rw',
19     isa => 'Str',
20     required => 1,
21     default => 'jp',
22     );
23    
24     has 'to' => (
25     is => 'rw',
26     isa => 'Str',
27     required => 1,
28     default => 'en',
29     );
30    
31     use Data::Dump qw/dump/;
32    
33     sub data {
34     my ( $self ) = @_;
35    
36     REST::Google::Translate->http_referer('http://localhost/');
37    
38     my $res = REST::Google::Translate->new(
39     q => $self->text,
40     langpair => $self->from . '|' . $self->to,
41     );
42    
43     die "response status failure", dump($res) if $res->responseStatus != 200;
44    
45     return $res->responseData->translatedText;
46     }
47    
48     1;

  ViewVC Help
Powered by ViewVC 1.1.26