TomNewbie has asked for the wisdom of the Perl Monks concerning the following question:

Initially I was working on adding reCAPTCHA to my site, but without success, so I tried with just the basic example script that is supplied with the Perl module, but again the same issue.

My shared hosting has a limited number of modules installed, HTML::Tiny.pm not being amongst them, so I had to manually install a localised copy within my web-space. Obviously not ideal but I didn't think this would be too much of a problem as it is lightweight and dependency free.

Anyway the error(s) I get in the browser are here below, some are 'blank' (they just have the timestamp and module name) for some reason. Then there are the Tiny.pm references (newlines added for readability):

"Software error: [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: [Tue Nov 9 18:20:21 2010] Tiny.pm: syntax error at HTML/Tiny.pm line 6 +31, near "return qq{$attr="" [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: [Tue Nov 9 18:20:21 2010] Tiny.pm: syntax error at HTML/Tiny.pm line 6 +31, next token ??? [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: [Tue Nov 9 18:20:21 2010] reCAPTCHA.pm: BEGIN failed--compilation abor +ted at Captcha/reCAPTCHA.pm line 7. BEGIN failed--compilation aborted + at captcha.cgi line 9."

This doesn't tell me much, does anyone else glean anything from these error messages? By the way, I haven't edited 'HTML::Tiny.pm' in any way and in the 'reCAPTCHA.pm' I have only commented-out "use warnings" statement, as the 'warnings.pm' isn't available on my shared hosting, but I use the "-w" switch.

Maybe I just need some debugging advice, or maybe there is some other error, I really don't know, this is driving me nuts. I thought it would be simple ;o)

Here is my code, I won't post the "HTML::Tiny" (v1.05) or "Captcha::reCAPTCHA" (v0.94) modules as they are huge and widely available:

#!/usr/bin/perl -w # Simple CGI Captcha # File Name: captcha_test.cgi #open(STDERR, ">&STDOUT"); use CGI::Carp qw(fatalsToBrowser); use strict; #use warnings; use Captcha::reCAPTCHA; use CGI::Simple; # Your reCAPTCHA keys from # https://www.google.com/recaptcha/admin/create use constant PUBLIC_KEY => '-----8<--------snipped----------8<-----'; use constant PRIVATE_KEY => '-----8<--------snipped----------8<-----'; $| = 1; my $q = CGI::Simple->new; my $c = Captcha::reCAPTCHA->new; my $error = undef; print "Content-type: text/html\n\n"; print <<EOT; <html> <body> <form action="http://mydomain.com/captcha.cgi" method="post"> EOT # Check response if ( $q->param( 'recaptcha_response_field' ) ) { my $result = $c->check_answer( PRIVATE_KEY, $ENV{'REMOTE_ADDR'}, $q->param( 'recaptcha_challenge_field' ), $q->param( 'recaptcha_response_field' ) ); if ( $result->{is_valid} ) { print "Yes!"; } else { $error = $result->{error}; } } # Generate the form print $c->get_html( PUBLIC_KEY, $error ); print <<EOT; <br/> <input type="submit" value="submit" /> </form> </body> </html> EOT

Replies are listed 'Best First'.
Re: HTML::Tiny and reCAPTCHA Modules - Unknown Error
by Anonymous Monk on Nov 10, 2010 at 01:11 UTC
    , so I had to manually install a localised copy within my web-space.Obviously not ideal but I didn't think this would be too much of a problem as it is lightweight and dependency free.

    Did you run the test suite?

      Sorry, I'm not sure exactly what you mean by the "test suite", could you please elaborate?

      I have run the 'captcha.cgi' script through a debug script, but didn't get any further information just a duplication of the same error messages I posted here.

      Also, the 'captcha.cgi' script I am trying to get running is just the example script supplied with the reCAPTCHA module. The only modifications I have made to it were to add the required keys and form action attribute.

      I don't suppose either of these is what you mean by "test suite"?