blib/lib/Mojolicious/Plugin/Captcha/reCAPTCHA.pm

filter: Statementstmt 31.5% 18 / 57 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 33.3% 5 / 15 Podpod 100% 1 / 1 totaltotal 24.4% 24 / 98 CC 10 SCAR 27.2
CC
10
Cov
23%
__ANON__
42.0
register
20.0
__ANON__
6.0
CRAP 15.1
↑ Summary
1 package Mojolicious::Plugin::Captcha::reCAPTCHA;
2  
3 # ABSTRACT: use Captcha::reCAPTCHA in Mojolicious apps
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Mojo::ByteStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Captcha::reCAPTCHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = 0.05;
13 1 $VERSION = eval $VERSION;
14  
15 0 ▶sub register {
Subroutine register: not called CC=4 SCAR=30.0
Pod documented
16 0 my $self = shift;
17 0 my $app = shift;
18 0 ▶ my $conf = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
19  
20 0 $app->log->debug("Usage of Mojolicious::Plugin::Captcha::reCAPTCHA is deprecated; you should consider switching to Mojolicious::Plugin::ReCAPTCHAv2");
21  
22 die ref($self), ": need private and public key\n"
23 0 ▶ unless $conf->{private_key} and $conf->{public_key};
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"private_key"} and $conf->{"public_key"} 0 0 0
Condition0%0/3
$conf->{"private_key"} and $conf->{"public_key"}
!ll&&!rl&&r
000
MC/DC0%0/2
$conf->{"private_key"} and $conf->{"public_key"}
$conf->{"private_key"} $conf->{"public_key"}
Truth table0%0/3
A and B
A= $conf->{"private_key"}B= $conf->{"public_key"}
ABresult
0X0
100
111
24  
25 $app->attr(
26 0 ▶ 'recaptcha_obj' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 Captcha::reCAPTCHA->new;
28 },
29 0 );
30  
31 0 ▶ $app->attr( recaptcha_private_key => sub { $conf->{private_key} } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 ▶ $app->attr( recaptcha_public_key => sub { $conf->{public_key} } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ $app->attr( recaptcha_use_ssl => sub { $conf->{use_ssl} } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ $app->attr( recaptcha_options => sub { $conf->{options} } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
35  
36 0 ▶ $app->helper( recaptcha => sub { return shift->app->recaptcha_obj } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 $app->helper(
38 0 ▶ use_recaptcha => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 my $self = shift;
40 0 $self->stash( recaptcha_html => $self->recaptcha_html(@_) );
41 0 return;
42 }
43 0 );
44 $app->helper(
45 0 ▶ recaptcha_html => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
46 0 my ( $self, $err, $use_ssl, $options ) = @_;
47 0 ▶ if ( !defined $use_ssl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $use_ssl) 0 0 0
48 0 ▶ if ( defined $self->app->recaptcha_use_ssl ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->app->recaptcha_use_ssl) { } 0 0 0
elsif ($self->req->url->base->scheme eq 'https' or $self->req->headers->header('X-Forwarded-Protocol') eq 'https') { } 0 0 0
49 0 $use_ssl = $self->app->recaptcha_use_ssl;
50 }
51 ▶ elsif ( $self->req->url->base->scheme eq 'https'
Condition0%0/3
$self->req->url->base->scheme eq "https" or $self->req->headers->header("X-Forwarded-Protocol") eq "https"
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->req->url->base->scheme eq "https" or $self->req->headers->header("X-Forwarded-Protocol") eq "https"
$self->req->url->base->scheme eq "https" $self->req->headers->header("X-Forwarded-Protocol") eq "https"
Truth table0%0/3
A or B
A= $self->req->url->base->scheme eq "https"B= $self->req->headers->header("X-Forwarded-Protocol") eq "https"
ABresult
1X1
011
000
52 or $self->req->headers->header('X-Forwarded-Protocol') eq 'https' )
53 {
54 0 $use_ssl = 1;
55 }
56 else {
57 0 $use_ssl = undef;
58 }
59 }
60 0 ▶ if ( !defined $options ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options) 0 0 0
61 0 $options = $self->app->recaptcha_options;
62 }
63 0 return Mojo::ByteStream->new(
64 $self->recaptcha->get_html( $self->app->recaptcha_public_key, $err, $use_ssl, $options )
65 );
66 }
67 0 );
68 $app->helper(
69 0 ▶ validate_recaptcha => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
70 0 my ( $self, $params ) = @_;
71  
72 my $result = $self->recaptcha->check_answer( $self->app->recaptcha_private_key,
73 $self->tx->remote_address,
74 $params->{recaptcha_challenge_field},
75 $params->{recaptcha_response_field},
76 0 );
77  
78 0 ▶ if ( !$result->{is_valid} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result->{"is_valid"}) 0 0 0
79 0 $self->stash( recaptcha_error => $result->{error} );
80 0 return 0;
81 }
82 0 return 1;
83 }
84 0 );
85  
86 0 return;
87 } ## end sub register
88  
89 1 1;
90  
91 __END__
↑ Summary