~ubuntu-branches/ubuntu/precise/libdata-entropy-perl/precise

« back to all changes in this revision

Viewing changes to lib/Data/Entropy/RawSource/RandomOrg.pm

  • Committer: Bazaar Package Importer
  • Author(s): Jotam Jr. Trejo
  • Date: 2011-05-08 16:44:11 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110508164411-te8qgrv79zsowhwa
Tags: 0.007-1
* New upstream release
* debian/rules: refresh, use tiny dh7 now
* debian/copyright: refresh according to DEP 5 revision 135, also
  update Ivan Kohler email
* debian/control: drop useless versioned perl dependency
* Switch to source format 3.0 (quilt)
* debian/control: bump Standards Version to 3.9.2
* debian/control: add libtest-pod-perl, libtest-pod-coverage-perl and
  libhttp-lite-perl to B-D-I, needed by some tests
* debian/control: remove libwww-perl from dependencies, upstream use
  HTTP::Lite instead of LWP now
* Add myself to Uploaders and Copyright
* Bump DH compat level to 8

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
use strict;
51
51
 
52
52
use Errno 1.00 qw(EIO);
53
 
use LWP 5.53_94;
54
 
use LWP::UserAgent;
 
53
use HTTP::Lite 2.2 ();
55
54
 
56
 
our $VERSION = "0.006";
 
55
our $VERSION = "0.007";
57
56
 
58
57
=head1 CONSTRUCTOR
59
58
 
68
67
 
69
68
sub new {
70
69
        my($class) = @_;
 
70
        my $http = HTTP::Lite->new;
 
71
        $http->http11_mode(1);
71
72
        return bless({
72
 
                ua => LWP::UserAgent->new,
 
73
                http => $http,
73
74
                buffer => "",
74
75
                bufpos => 0,
75
76
                error => 0,
127
128
 
128
129
sub _checkbuf {
129
130
        my($self) = @_;
130
 
        my $response =
131
 
                $self->{ua}->get("http://www.random.org/cgi-bin/checkbuf");
132
 
        unless($response->code == 200) {
 
131
        $self->{http}->reset;
 
132
        unless($self->{http}->request(
 
133
                "http://www.random.org/cgi-bin/checkbuf"
 
134
        ) == 200) {
133
135
                $! = EIO;
134
136
                return undef;
135
137
        }
136
 
        my $content = $response->content;
137
 
        unless($content =~ /\A[\ \t\n]*([0-9]{1,3})\%[\ \t\n]*\z/) {
 
138
        unless($self->{http}->body =~
 
139
                        /\A[\ \t\n]*([0-9]{1,3}(?:\.[0-9]+)?)\%[\ \t\n]*\z/) {
138
140
                $! = EIO;
139
141
                return undef;
140
142
        }
153
155
                }
154
156
                sleep 10;
155
157
        }
156
 
        my $response = $self->{ua}->get(
157
 
                "http://www.random.org/cgi-bin/randbyte?nbytes=256&format=f");
158
 
        unless($response->code == 200) {
 
158
        $self->{http}->reset;
 
159
        unless($self->{http}->request(
 
160
                "http://www.random.org/cgi-bin/randbyte?nbytes=256&format=f"
 
161
        ) == 200) {
159
162
                $! = EIO;
160
163
                return 0;
161
164
        }
162
 
        $self->{buffer} = $response->content;
 
165
        $self->{buffer} = $self->{http}->body;
163
166
        $self->{bufpos} = 0;
164
167
        if($self->{buffer} !~ /\A[\x00-\xff]+\z/) {
165
168
                $self->{buffer} = "";
256
259
 
257
260
=head1 COPYRIGHT
258
261
 
259
 
Copyright (C) 2006, 2007, 2009 Andrew Main (Zefram) <zefram@fysh.org>
 
262
Copyright (C) 2006, 2007, 2009, 2011
 
263
Andrew Main (Zefram) <zefram@fysh.org>
260
264
 
261
265
=head1 LICENSE
262
266