| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Business::WebMoney::Exchanger; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30122
|
use 5.008000; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
46
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
40
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
901
|
use Business::WebMoney; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Carp; |
|
12
|
|
|
|
|
|
|
use LWP::UserAgent; |
|
13
|
|
|
|
|
|
|
use XML::LibXML; |
|
14
|
|
|
|
|
|
|
use HTTP::Request; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
|
17
|
|
|
|
|
|
|
{ |
|
18
|
|
|
|
|
|
|
my ($class, @args) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $opt = Business::WebMoney::parse_args(\@args, { |
|
21
|
|
|
|
|
|
|
timeout => 20, |
|
22
|
|
|
|
|
|
|
}); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $self = { |
|
25
|
|
|
|
|
|
|
timeout => $opt->{timeout}, |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return bless $self, $class; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub best_rates |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
|
|
|
|
|
|
my ($self, @args) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{errstr} = undef; |
|
36
|
|
|
|
|
|
|
$self->{errcode} = undef; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $req_fields = Business::WebMoney::parse_args(\@args, { |
|
39
|
|
|
|
|
|
|
debug_response => undef, |
|
40
|
|
|
|
|
|
|
}); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $res = eval { |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
local $SIG{__DIE__}; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $res_content; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
unless ($res_content = $req_fields->{debug_response}) { |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
51
|
|
|
|
|
|
|
$ua->timeout($self->{timeout}); |
|
52
|
|
|
|
|
|
|
$ua->env_proxy; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $req = HTTP::Request->new; |
|
55
|
|
|
|
|
|
|
$req->method('GET'); |
|
56
|
|
|
|
|
|
|
$req->uri('https://wm.exchanger.ru/asp/XMLbestRates.asp'); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $res = $ua->request($req); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
unless ($res->is_success) { |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->{errcode} = $res->code; |
|
63
|
|
|
|
|
|
|
$self->{errstr} = $res->message; |
|
64
|
|
|
|
|
|
|
return undef; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$res_content = $res->content; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $parser = XML::LibXML->new; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $doc = $parser->parse_string($res_content); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my %result; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
for my $node ($doc->getElementsByTagName('row')) { |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my ($from, $to, %row); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
for my $attr ($node->attributes) { |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $key = $attr->name; |
|
83
|
|
|
|
|
|
|
my $value = $attr->value; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if ($key eq 'Direct') { |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
($from, $to) = ($value =~ /^(\S+?)\s*-\s*(\S+)$/); |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} elsif ($key eq 'BaseRate') { |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$row{rate} = ($value > 0) ? ($value + 0) : (-1 / $value); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} elsif (my ($percent) = ($key =~ /^Plus(\d+)$/)) { |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# 005 => 0.05 |
|
96
|
|
|
|
|
|
|
# 01 => 0.1 |
|
97
|
|
|
|
|
|
|
# 02 => 0.2 |
|
98
|
|
|
|
|
|
|
# ... |
|
99
|
|
|
|
|
|
|
# 1 => 1 |
|
100
|
|
|
|
|
|
|
# 2 => 2 |
|
101
|
|
|
|
|
|
|
# ... |
|
102
|
|
|
|
|
|
|
$percent =~ s/^0(0*)/0.$1/; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$row{$percent} = $value; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$row{$key} = $value; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
if ($from && $to && $row{rate}) { |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$result{$from}->{$to} = \%row; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
\%result; |
|
119
|
|
|
|
|
|
|
}; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if ($@) { |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->{errcode} = -1000; |
|
124
|
|
|
|
|
|
|
$self->{errstr} = $@; |
|
125
|
|
|
|
|
|
|
return undef; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
return $res; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub errcode |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
|
|
|
|
|
|
my ($self) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
return $self->{errcode}; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub errstr |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
|
|
|
|
|
|
my ($self) = @_; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
return $self->{errstr}; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |