line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::GetVolatileData; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
98250
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
68
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
83
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
998
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
51105
|
|
|
2
|
|
|
|
|
50
|
|
8
|
2
|
|
|
2
|
|
15
|
use Carp qw/croak/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
730
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT = qw(get_data); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '1.0102'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $ERROR; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub get_data { |
19
|
6
|
|
|
6
|
1
|
16018
|
undef $ERROR; |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
18
|
my $url = shift; |
22
|
6
|
|
|
|
|
18
|
my %args = @_; |
23
|
|
|
|
|
|
|
|
24
|
6
|
100
|
|
|
|
34
|
$args{num} = 1 unless exists $args{num}; |
25
|
6
|
50
|
|
|
|
46
|
$args{num} =~ /\A\d+\z/ |
26
|
|
|
|
|
|
|
or croak q{'num' argument can take only positive integers}; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
69
|
my $res = LWP::UserAgent->new( |
29
|
|
|
|
|
|
|
agent => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) ' |
30
|
|
|
|
|
|
|
. 'Gecko/20100101 Firefox/26.0', |
31
|
|
|
|
|
|
|
timeout => 30, |
32
|
|
|
|
|
|
|
)->get( $url ); |
33
|
|
|
|
|
|
|
|
34
|
6
|
100
|
|
|
|
2327774
|
unless ( $res->is_success ) { |
35
|
2
|
|
|
|
|
36
|
$ERROR = 'Network error: ' . $res->status_line; |
36
|
2
|
|
|
|
|
64
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
101
|
my $c = $res->decoded_content; |
40
|
4
|
50
|
|
|
|
5450
|
my @data = split /\n/, defined($c) ? $c : ''; |
41
|
4
|
50
|
|
|
|
25
|
@data or do { $ERROR = 'Got empty data'; return }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
42
|
4
|
|
|
|
|
12
|
my @return; |
43
|
4
|
|
|
|
|
22
|
for ( 1.. $args{num} ) { |
44
|
10
|
100
|
|
|
|
30
|
@data or last; |
45
|
9
|
|
|
|
|
94
|
push @return, splice @data, int(rand @data), 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
4
|
100
|
|
|
|
200
|
return @return > 1 ? @return : $return[0]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
q| |
53
|
|
|
|
|
|
|
Knock knock. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Race condition. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Who's there? |
58
|
|
|
|
|
|
|
|; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |