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

In reply to HTML::Tiny and reCAPTCHA Modules - Unknown Error by TomNewbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.