blib/lib/Catalyst/TraitFor/Controller/reCAPTCHA.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 60.0% 6 / 10 Conditioncond 50.0% 6 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 78.4% 69 / 88 CC 11 SCAR 19.8
CC
11
Cov
80%
captcha_check
14.2
captcha_get
3.0
BEGIN
1.0
CRAP 7.2
↑ Summary
1 package Catalyst::TraitFor::Controller::reCAPTCHA;
2 # ABSTRACT: authenticate people and read books!
3 2 $Catalyst::TraitFor::Controller::reCAPTCHA::VERSION = '2.00';
4 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use MooseX::MethodAttributes::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Captcha::reCAPTCHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶has recaptcha => ( is => 'ro', default => sub { Captcha::reCAPTCHA->new } );
Subroutine __ANON__: called CC=1 SCAR=0.0
12  
13 2 ▶sub captcha_get :Private {
Subroutine captcha_get: called CC=3 SCAR=11.0
Pod documented
14 2 my ( $self, $c ) = @_;
15 2 my $recaptcha;
16  
17 2 ▶ if (lc($c->config->{recaptcha}{version} || '') eq 'v2') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($c->config->{'recaptcha'}{'version'} || '') eq 'v2') { } 1 1 2
Condition100%2/2
$c->config->{'recaptcha'}{'version'} || ''
l!l
11
MC/DC100%1/1
$c->config->{'recaptcha'}{'version'} || ''
$c->config->{'recaptcha'}{'version'}
Truth table100%2/2
A
A= $c->config->{'recaptcha'}{'version'}
Aresult
11
00
18 $recaptcha = $self->recaptcha->get_html_v2(
19 $c->config->{recaptcha}{pub_key},
20 $c->config->{recaptcha}{options}
21 1 );
22 }
23 else {
24 $recaptcha = $self->recaptcha->get_html(
25 $c->config->{recaptcha}{pub_key},
26 $c->stash->{recaptcha_error},
27 $c->req->secure,
28 $c->config->{recaptcha}{options}
29 1 );
30 }
31  
32 2 $c->stash( recaptcha => $recaptcha );
33 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶sub captcha_check :Private {
Subroutine captcha_check: called CC=9 SCAR=26.5
Pod documented
36 1 my ( $self, $c ) = @_;
37  
38 1 my $challenge = $c->req->param('recaptcha_challenge_field');
39 1 my $response = $c->req->param('recaptcha_response_field');
40 1 my $response_v2 = $c->req->param('g-recaptcha-response');
41  
42 1 ▶ unless ( ($response && $challenge || $response_v2)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response and $challenge or $response_v2) 0 1 1
Condition33%2/6
$response and $challenge or $response_v2
l!l&&r!l&&!r
100
$response and $challenge
!ll&&!rl&&r
001
MC/DC0%0/3
$response and $challenge or $response_v2
$response $challenge $response_v2
Truth table20%1/5
A and B or C
A= $responseB= $challengeC= $response_v2
ABCresult
11X1
0X11
1011
0X00
1000
43 0 $c->stash->{recaptcha_error} = 'User appears not to have submitted a recaptcha';
44 0 return;
45 }
46  
47 1 my $res;
48 1 ▶ if (lc($c->config->{recaptcha}{version} || '') eq 'v2') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($c->config->{'recaptcha'}{'version'} || '') eq 'v2') { } 0 1 1
Condition50%1/2
$c->config->{'recaptcha'}{'version'} || ''
l!l
01
MC/DC0%0/1
$c->config->{'recaptcha'}{'version'} || ''
$c->config->{'recaptcha'}{'version'}
Truth table50%1/2
A
A= $c->config->{'recaptcha'}{'version'}
Aresult
11
00
49 0 $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = $c->req->secure;
50 $res = $self->recaptcha->check_answer_v2(
51 $c->config->{recaptcha}{priv_key},
52 0 $response_v2,
53 $c->req->address
54 );
55 }
56 else {
57 $res = $self->recaptcha->check_answer(
58 $c->config->{recaptcha}{priv_key},
59 1 $c->req->address,
60 $challenge,
61 $response
62 );
63 }
64  
65 1 ▶ croak 'Failed to get valid result from reCaptcha'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $res eq "HASH" 0 1 1
66 unless ref $res eq 'HASH';
67  
68 1 ▶ unless ( $res->{is_valid} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"is_valid"}) 1 0 1
69 1 ▶ $c->stash( recaptcha_error => $res->{error} || 'Invalid recaptcha' );
Condition50%1/2
$res->{'error'} || 'Invalid recaptcha'
l!l
10
MC/DC0%0/1
$res->{'error'} || 'Invalid recaptcha'
$res->{'error'}
Truth table50%1/2
A
A= $res->{'error'}
Aresult
11
00
70 }
71  
72 1 $c->stash( recaptcha_ok => $res->{is_valid} );
73 1 return $res->{is_valid};
74 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 2 1;
77  
78 __END__
↑ Summary