line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Math::Google; |
2
|
1
|
|
|
1
|
|
32945
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
83
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.2 $ =~ /(\d+)/g; |
7
|
1
|
|
|
1
|
|
782
|
use URI; |
|
1
|
|
|
|
|
8184
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5259
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
89229
|
|
|
1
|
|
|
|
|
319
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new{ |
11
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
12
|
0
|
|
0
|
|
|
|
my $self = shift || {}; |
13
|
0
|
|
0
|
|
|
|
$self->{base_uri} ||= 'http://www.google.com/search'; |
14
|
0
|
0
|
|
|
|
|
unless ($self->{ua}){ |
15
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
16
|
0
|
|
|
|
|
|
$ua->agent( __PACKAGE__ . '/' . $VERSION ); |
17
|
0
|
|
|
|
|
|
$self->{ua} = $ua; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
return bless $self, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub calc{ |
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
0
|
|
|
|
|
|
my $query = shift; |
25
|
0
|
|
|
|
|
|
my $as_equation = shift; |
26
|
0
|
|
|
|
|
|
my $uri = URI->new($self->{base_uri}); |
27
|
0
|
|
|
|
|
|
$uri->query_form( q => $query); |
28
|
0
|
|
|
|
|
|
my $res = $self->{ua}->get($uri); |
29
|
0
|
0
|
|
|
|
|
return unless $res->code == 200; |
30
|
0
|
|
|
|
|
|
my $ans = $res->content; |
31
|
0
|
|
|
|
|
|
$ans =~ s{.*/images/calc_img.gif}{}xmso; |
32
|
0
|
|
|
|
|
|
$ans =~ s{.*?}{}xmso; |
33
|
0
|
|
|
|
|
|
$ans =~ s{.*}{}xmso; |
34
|
0
|
0
|
|
|
|
|
return $ans if $as_equation; |
35
|
0
|
|
|
|
|
|
$ans =~ s{.*=\s+}{}xmso; |
36
|
0
|
|
|
|
|
|
return $ans; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |