Skip Menu |

This queue is for tickets about the WWW-Babelfish CPAN distribution.

Report information
The Basics
Id: 13934
Status: open
Priority: 0/
Queue: WWW-Babelfish

People
Owner: Nobody in particular
Requestors: ermeyers [...] adelphia.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.12
Fixed in: (no value)



Subject: Module corrupts main::$_
If Conditionals such as if ( m/.../ ) break when main::$_ is changed by the module. Automated Babelfish service at Altavista is not working well. Google service is great, but has a smaller set of conversions. ------------------ Hello Dan, First let me tell you that I have a patch file attached. I've used your module before, but things have changed, and my application is different today, then what it was back when. Now let me explain that I had a miserable time with the module, for two very different reasons. First the module was corrupting the main package space, specifically $_, and my if conditionals using $_ were failing to match up, when I new that they should have matched. Second the Babelfish server, at Altavista, sucks at best! I switched to Google and got very good (robust) performance out of the module, with my modifications. I hope that these changes will take you to beta. I'll also submit a bug report. Eric -- Eric R. Meyers Systems Engineer GPG: 0x83CE80A3 http://users.adelphia.net/~ermeyers
--- /usr/lib/perl5/site_perl/5.8.6/WWW/Babelfish.pm 2003-10-19 00:33:55.000000000 -0400 +++ WWW/Babelfish.pm 2005-07-30 23:17:27.000000000 -0400 @@ -156,7 +156,10 @@ my ($self, %params) = @_; # Paragraph separator is "\n\n" by default - $/ = $params{delimiter} || "\n\n"; + local $/ = $params{delimiter} || "\n\n"; + local $_; + + $params{delimiter} = "\n\n" if ( ! defined( $params{delimiter} ) ); undef $self->{error}; unless( exists($self->{Langs}->{$params{source}}) ){ @@ -214,7 +217,7 @@ if ($para =~ s/(^\s+)(\S)/$2/) { $para_start_ws = $1 || ""; } - chomp $para; # Remove the para delimiter + $para =~ s/$params{delimiter}//; # Remove the para delimiter CHUNK: foreach $chunk ( $self->_chunk_text($MAXCHUNK, $para) ) { @@ -229,7 +232,13 @@ #$text = $self->_extract_text($res->as_string); #REMOVE $text = &{ $Services->{ $self->{service} }->{extract_text} }($res->as_string); - next RETRY if $text =~ /^\*\*time-out\*\*/; # in-band signalling; yuck + if ( ( ! defined( $text ) ) || + ( $text =~ /^\*\*time-out\*\*/ ) + ) # in-band signalling; yuck + { + next RETRY; + + } ## end if $text =~ s/\n$//; # Babelfish likes to append newlines $transpara .= $text;
Subject: Module corrupts global $_
RT-Send-CC: durist [...] frii.com
While Eric's patch seems to have been applied in the current version 0.13 of WWW::Babelfish, the module still modifies the global $_ in its extract_text routines. You'll find fix for this including a test in the patch attached. Regards, fany
--- WWW-Babelfish-0.13/Babelfish.pm 2005-08-07 04:58:35.000000000 +0200 +++ WWW-Babelfish-0.13.1/Babelfish.pm 2006-03-14 07:50:13.000000000 +0100 @@ -14,7 +14,7 @@ # Do not simply export all your public functions/methods/constants. @EXPORT = qw(); -$VERSION = '0.13'; +$VERSION = '0.13.1'; # Preloaded methods go here. @@ -52,10 +52,9 @@ extract_text => sub { my($html) = @_; my $p = HTML::TokeParser->new(\$html); - my $tag; - while ($tag = $p->get_tag('input')) { - $_ = @{$tag}[1]->{value} if @{$tag}[1]->{name} eq 'q'; - return decode("utf8",$_); + while ( my $tag = $p->get_tag('input') ) { + my $text = @{$tag}[1]->{value} if @{$tag}[1]->{name} eq 'q'; + return decode("utf8",$text); } } }, @@ -81,8 +80,8 @@ my $tag; while ($tag = $p->get_tag('textarea')) { if(@{$tag}[1]->{name} eq 'q'){ - $_ = $p->get_text; - return decode("utf8",$_); + my $text = $p->get_text; + return decode("utf8",$text); } } } @@ -130,13 +129,12 @@ # Incredibly, this works for both Babelfish and Google; it should really # be a method in $Services my $p = HTML::TokeParser->new(\$page); - my $a2b; if( $p->get_tag("select") ){ - while( $_ = $p->get_tag("option") ){ - $a2b = $p->get_trimmed_text; + while( my $option_tag = $p->get_tag('option') ){ + my $a2b = $p->get_trimmed_text; next if $a2b =~ /Select from and to languages/; # This for babelfish $a2b =~ /(\S+)\sto\s(\S+)/ or next; - $self->{Langs}{$1}{$2} = $_->[1]{value}; + $self->{Langs}{$1}{$2} = $option_tag->[1]{value}; $self->{Langs}{$2} ||= {}; } } --- WWW-Babelfish-0.13/test.pl 2005-08-07 04:39:39.000000000 +0200 +++ WWW-Babelfish-0.13.1/test.pl 2006-03-14 07:45:20.000000000 +0100 @@ -3,10 +3,10 @@ ######################### We start with some black magic to print on failure. -# Change 1..1 below to 1..last_test_to_print . +# Change 1..2 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) -BEGIN { $| = 1; print "1..1\n"; } +BEGIN { $_ = 'UnderScore'; $| = 1; print "1..2\n"; } END {print "not ok 1\n" unless $loaded;} use WWW::Babelfish; $loaded = 1; @@ -48,3 +48,5 @@ print "Translation: ", $trans, "\n"; } + +print +( $_ ne 'UnderScore' && 'not ' ) . "ok 2\n";