blib/lib/Web/VWF/Display/captcha.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 72 CC 5 SCAR 28.7
CC
5
Cov
0%
html
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 17.6
1 package Web::VWF::Display::captcha;
2  
3 use strict;
4 use warnings;
5  
6 use version; our $VERSION = version->declare('0.003.0');
7 use parent 'Web::VWF::Display';
8  
9 sub html {
10 my $self = shift;
11 my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
12  
13 my $config = $self->{'config'} or die "Missing 'config' handle";
14 $self->{'info'} or die "Missing 'info' handle";
15  
16 # Get reCAPTCHA configuration
17 my $recaptcha_config = $config->recaptcha();
18 unless ($recaptcha_config && $recaptcha_config->{enabled}) {
19 die 'reCAPTCHA is not enabled in configuration';
20 }
21  
22 my $site_key = $recaptcha_config->{site_key};
23 my $script_name = $ENV{'SCRIPT_NAME'} || '/cgi-bin/page.fcgi';
24  
25 # Get rate limit info for display
26 my $soft_limit = $config->{'security'}->{'rate_limiting'}->{'max_requests'} || 100;
27 my $time_window = $config->{'security'}->{'rate_limiting'}->{'time_window'} || '60s';
28 $time_window =~ s/s$//; # Remove 's' suffix
29  
30 # Determine if this is a hard block or soft limit
31 my $is_hard_block = $args{'hard_block'} || 0;
32 my $request_count = $args{'request_count'} || 0;
33  
34 if ($self->{'logger'}) {
35 $self->{'logger'}->debug('Displaying CAPTCHA page for ' . ($is_hard_block ? 'hard block' : 'soft limit'));
36 }
37  
38 return $self->SUPER::html({
39 site_key => $site_key,
40 script_name => $script_name,
41 soft_limit => $soft_limit,
42 time_window => $time_window,
43 is_hard_block => $is_hard_block,
44 request_count => $request_count,
45 });
46 }
47  
48 1;
49  
50 =encoding utf8
51  
52 =head1 NAME
53  
54 Web::VWF::Display::captcha - The page that asks a client to prove it is a person
55  
56 =head1 VERSION
57  
58 Version 0.003.0
59  
60 =head1 DESCRIPTION
61  
62 Shown by L<Web::VWF> and not by C<?page=>, when a client goes over the soft rate
63 limit (see C<security.rate_limiting> in L<Web::VWF/CONFIGURATION>), and again,
64 with C<hard_block> set, with the hard limit's warning when reCAPTCHA is enabled.
65 The answer comes back as C<g-recaptcha-response>, which L<Web::VWF::CAPTCHA>
66 checks.
67  
68 =head1 METHODS
69  
70 =head2 html
71  
72 Takes C<hard_block> and C<request_count>, both optional, which are only shown to
73 the client. Dies when reCAPTCHA is not enabled or the object has no C<config> or
74 C<info>. The template is F<captcha.tmpl>; it is given C<site_key>,
75 C<script_name> and the limits.
76  
77 =head3 API SPECIFICATION
78  
79 =head4 INPUT
80  
81 { hard_block => { type => 'boolean', optional => 1 }, request_count => { type => 'integer', optional => 1 } }
82  
83 =head4 OUTPUT
84  
85 { type => 'string' } # the HTML
86  
87 =head1 AUTHOR
88  
89 Nigel Horne, C<< <njh at nigelhorne.com> >>
90  
91 =head1 LICENCE AND COPYRIGHT
92  
93 Copyright 2010-2026 Nigel Horne.
94  
95 Usage is subject to the GPL2 licence terms.
96 If you use it,
97 please let me know.
98  
99 =cut