line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::reCAPTCHA::v3; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.1.0'; |
4
|
1
|
|
|
1
|
|
575
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use Carp qw(croak carp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
434
|
use LWP; |
|
1
|
|
|
|
|
39258
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
441
|
use HTTP::Request::Common qw(POST); |
|
1
|
|
|
|
|
1881
|
|
|
1
|
|
|
|
|
51
|
|
10
|
1
|
|
|
1
|
|
548
|
use JSON qw( decode_json ); |
|
1
|
|
|
|
|
6713
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
99
|
use vars qw($AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
378
|
|
13
|
|
|
|
|
|
|
my %allowed = ( |
14
|
|
|
|
|
|
|
request_url => 'https://www.google.com/recaptcha/api/siteverify', |
15
|
|
|
|
|
|
|
secret => undef, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
1
|
|
my $that = shift; |
21
|
0
|
|
0
|
|
|
|
my $class = ref($that) || $that; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $self = { |
24
|
|
|
|
|
|
|
_permitted => \%allowed, |
25
|
|
|
|
|
|
|
%allowed, |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
bless $self, $class; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my ($args) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->_init($args); |
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub AUTOLOAD { |
37
|
0
|
|
|
0
|
|
|
my $self = shift; |
38
|
0
|
0
|
|
|
|
|
my $type = ref($self) |
39
|
|
|
|
|
|
|
or croak "$self is not an object"; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $name = $AUTOLOAD; |
42
|
0
|
|
|
|
|
|
$name =~ s/.*://; #strip fully qualifies portion |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless ( exists $self->{_permitted}->{$name} ) { |
45
|
0
|
|
|
|
|
|
croak "Can't access '$name' field in object of class $type"; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
0
|
|
|
|
|
if (@_) { |
48
|
0
|
|
|
|
|
|
return $self->{$name} = shift; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
|
return $self->{$name}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _init { |
56
|
0
|
|
|
0
|
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my ($args) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(exists($args->{-secret})){ |
60
|
0
|
|
|
|
|
|
$self->secret($args->{-secret}); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
0
|
|
|
|
|
|
carp "You'll need to pass the Google reCAPTCHA v3 secret key to new()"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub request { |
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my ($args) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if(!exists($args->{-response})){ |
75
|
0
|
|
|
|
|
|
carp 'you will need to pass your response in -response to request()'; |
76
|
0
|
|
|
|
|
|
return undef; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $req_params = { |
80
|
|
|
|
|
|
|
response => $args->{-response}, |
81
|
0
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if(exists($args->{-remoteip})){ |
84
|
0
|
|
|
|
|
|
$req_params->{remoteip} = $args->{-remoteip}; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
0
|
|
|
|
|
if(defined($self->secret)){ |
87
|
0
|
|
|
|
|
|
$req_params->{secret} = $self->secret; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
my $req = POST $self->request_url(), [%{$req_params}]; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $json = JSON->new->allow_nonref; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return $json->decode( |
94
|
|
|
|
|
|
|
$ua->request($req)->decoded_content |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |