line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Role::Captcha; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1383
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
61
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
499
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use IO::Interactive qw(is_interactive); |
9
|
|
|
|
|
|
|
use Term::ReadKey; |
10
|
|
|
|
|
|
|
use Try::Tiny; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_captcha { |
13
|
|
|
|
|
|
|
my ($self) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return 0 |
16
|
|
|
|
|
|
|
unless is_interactive(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $captcha_object = $self->build_object('Captcha'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
CAPTCHA: |
21
|
|
|
|
|
|
|
for (1..3) { |
22
|
|
|
|
|
|
|
my $captcha_data = $captcha_object->fetch(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $captcha_solution; |
25
|
|
|
|
|
|
|
say "Please solve the captcha image at ".$captcha_data->{url}; |
26
|
|
|
|
|
|
|
while ( not defined( $captcha_solution = ReadLine(-1) ) ) { |
27
|
|
|
|
|
|
|
# no key pressed yet |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
chomp($captcha_solution); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return 0 |
33
|
|
|
|
|
|
|
if $captcha_solution =~ /^\s*$/; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $captcha_ok = 0; |
36
|
|
|
|
|
|
|
try { |
37
|
|
|
|
|
|
|
$self->log('debug','Solving captcha %s with %s',$captcha_object->guid,$captcha_solution); |
38
|
|
|
|
|
|
|
$captcha_object->solve($captcha_solution); |
39
|
|
|
|
|
|
|
$captcha_ok = 1; |
40
|
|
|
|
|
|
|
} catch { |
41
|
|
|
|
|
|
|
$self->log('error','Captcha solution for %s not valid',$captcha_object->guid); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
return 1 |
45
|
|
|
|
|
|
|
if $captcha_ok; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding utf8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Games::Lacuna::Role::Captcha -Â Handle captchas |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This method is used by the client to fetch captchas and present them to the |
62
|
|
|
|
|
|
|
user if possible |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |