line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::YahooJPN::QuoteDetail; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24097
|
use 5.008003; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
66
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
48
|
|
6
|
1
|
|
|
1
|
|
12
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
107
|
|
7
|
1
|
|
|
1
|
|
7172
|
use HTML::TableExtract; |
|
1
|
|
|
|
|
31985
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
30204
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
127551
|
|
|
1
|
|
|
|
|
1991
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; # 2004-04-12 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new(){ |
14
|
1
|
|
|
1
|
0
|
16
|
my ($class,$option) = @_; |
15
|
1
|
|
|
|
|
3
|
my $self = {}; |
16
|
1
|
|
|
|
|
4
|
bless $self,$class; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
2
|
foreach my $key (keys %{$option}) { |
|
1
|
|
|
|
|
4
|
|
19
|
2
|
|
|
|
|
4
|
my $lowercase = $key; |
20
|
2
|
|
|
|
|
4
|
$lowercase =~ tr/A-Z/a-z/; |
21
|
2
|
50
|
66
|
|
|
16
|
unless ($lowercase eq 'symbol' or $lowercase eq 'proxy' or $lowercase eq 'market') { |
|
|
|
66
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
croak "Invalid attribute name: $key"; |
23
|
|
|
|
|
|
|
} |
24
|
2
|
|
|
|
|
12
|
$$self{$lowercase} = $$option{$key}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
50
|
33
|
|
|
9
|
unless ($$self{'symbol'} =~ /^\d{4}$/ || $$self{'symbol'} =~ /^\d{4}\.[a-zA-Z]$/) { |
28
|
0
|
|
|
|
|
0
|
croak "The 'symbol' attribute must not be omitted .A stock symbol should be given with four numbers. (ex. `6758' or '6758.t' )"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
13
|
if($$self{symbol} =~ /^(\d{4})\.([a-zA-Z])$/) { |
|
|
50
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
$$self{'symbol'} = $1; |
33
|
0
|
|
|
|
|
0
|
$$self{'market'} = $2; |
34
|
|
|
|
|
|
|
}elsif($$self{symbol} =~ /^(\d{4})$/){ |
35
|
1
|
50
|
33
|
|
|
11
|
unless($$self{'market'} && $$self{'market'} =~ /^[a-zA-Z]$/){ |
36
|
0
|
|
|
|
|
0
|
croak "The 'market' attribute must not be omitted "; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
5
|
$$self{'url'} = 'http://quote.yahoo.co.jp/q?s='.$$self{'symbol'}.'&d='.$$self{'market'}; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
3
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub check(){ |
46
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
print "proxy is "; |
49
|
0
|
|
|
|
|
0
|
print $$self{'proxy'}; |
50
|
0
|
|
|
|
|
0
|
print "\n"; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
print "symbol is "; |
53
|
0
|
|
|
|
|
0
|
print $$self{'symbol'}; |
54
|
0
|
|
|
|
|
0
|
print "\n"; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
print "url is "; |
57
|
0
|
|
|
|
|
0
|
print $$self{'url'}; |
58
|
0
|
|
|
|
|
0
|
print "\n"; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub quote(){ |
63
|
1
|
|
|
1
|
0
|
793
|
my $self = shift; |
64
|
1
|
|
|
|
|
4
|
my $html_string = $self->_access_to_yahoo; |
65
|
1
|
|
|
|
|
8
|
$$self{'string_ref'} = $self->_extract_data_from_table(); |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
6
|
$self->_set_last_trade(); |
68
|
1
|
|
|
|
|
5
|
$self->_set_high_price(); |
69
|
1
|
|
|
|
|
5
|
$self->_set_low_price(); |
70
|
1
|
|
|
|
|
3
|
$self->_set_prev_close(); |
71
|
1
|
|
|
|
|
4
|
$self->_set_volume(); |
72
|
1
|
|
|
|
|
4
|
$self->_set_change(); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub quick_quote(){ |
77
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
78
|
0
|
|
|
|
|
0
|
my $html_string = $self->_access_to_yahoo; |
79
|
0
|
|
|
|
|
0
|
$$self{'string_ref'} = $self->_extract_data_from_table(); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _access_to_yahoo(){ |
83
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#Create a user agent object |
86
|
1
|
|
|
|
|
12
|
my $ua = LWP::UserAgent->new(env_proxy => 1, |
87
|
|
|
|
|
|
|
keep_alive => 1, |
88
|
|
|
|
|
|
|
timeout => 30, |
89
|
|
|
|
|
|
|
); |
90
|
1
|
50
|
|
|
|
50951
|
$ua->proxy(['http'], $$self{'proxy'}) if $$self{'proxy'}; |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
6
|
$ua->agent("MyApp/0.1"); |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
84
|
my $req = HTTP::Request->new(GET=>$$self{'url'}); |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
12352
|
$req->content_type('application/x-www-form-urlencoded'); |
97
|
1
|
|
|
|
|
108
|
$req->content(''); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Pass request to the user agent and get a response back |
100
|
1
|
|
|
|
|
30
|
my $res = $ua->request($req); |
101
|
|
|
|
|
|
|
|
102
|
1
|
50
|
|
|
|
2419493
|
if ($res->is_success) { |
103
|
1
|
|
|
|
|
24
|
$$self{'_html_string'} = $res->content; |
104
|
1
|
|
|
|
|
277
|
return 1; |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
|
|
|
0
|
$$self{'error_msg'} = "Cannot access to Yahoo!"; |
107
|
0
|
|
|
|
|
0
|
return 0; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _extract_data_from_table(){ |
112
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
12
|
my $te = new HTML::TableExtract; |
115
|
1
|
|
|
|
|
164
|
my $string = ""; |
116
|
1
|
|
|
|
|
3
|
my $ts = ""; |
117
|
1
|
|
|
|
|
2
|
my $line = ""; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
7
|
$te->parse($$self{'_html_string'}); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Examine all matching tables |
122
|
1
|
|
|
|
|
27836
|
foreach $ts ($te->table_states) { |
123
|
|
|
|
|
|
|
|
124
|
5
|
50
|
33
|
|
|
97
|
if( $ts->depth eq "1" && $ts->count eq "3" || |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
125
|
|
|
|
|
|
|
$ts->depth eq "0" && $ts->count eq "5" ){ |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
0
|
foreach my $row ($ts->rows) { |
128
|
0
|
|
|
|
|
0
|
$string = join(' ', @$row); |
129
|
0
|
|
|
|
|
0
|
$string =~ s/\n//g; |
130
|
0
|
|
|
|
|
0
|
$string =~ s/\r//g; |
131
|
0
|
|
|
|
|
0
|
$line .= $string; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
1
|
|
|
|
|
20
|
$$self{'_string'} = $line; |
136
|
1
|
|
|
|
|
168
|
return \$line; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub get_symbol_name(){ |
140
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
141
|
0
|
0
|
|
|
|
0
|
return $$self{'symbol_name'} if $$self{'symbol_name'}; |
142
|
0
|
|
|
|
|
0
|
$self->_set_symbol_name(); |
143
|
0
|
|
|
|
|
0
|
return $$self{'symbol_name'}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _set_symbol_name(){ |
147
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
148
|
0
|
|
|
|
|
0
|
$$self{'_string'} =~ m/^.([^\x20]+)/o; |
149
|
0
|
|
|
|
|
0
|
my $name = $1; |
150
|
0
|
|
|
|
|
0
|
$name =~ s/\(/ \(/; |
151
|
0
|
|
|
|
|
0
|
$name =~ s/\)/\) /; |
152
|
0
|
|
|
|
|
0
|
$$self{'symbol_name'} = $name; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub get_last_trade_price(){ |
156
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
157
|
0
|
0
|
|
|
|
0
|
return $$self{'last_trade_price'} if $$self{'last_trade_price'}; |
158
|
0
|
|
|
|
|
0
|
$$self{'_string'} =~ m/(\xbc\xe8\xb0\xfa\xc3\xcd)(\d+:\d+) ([\d\,]+)/o; |
159
|
0
|
|
|
|
|
0
|
$self->_set_last_trade(); |
160
|
0
|
|
|
|
|
0
|
return $3; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub get_last_trade_time(){ |
164
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
165
|
0
|
0
|
|
|
|
0
|
return $$self{'last_trade_time'} if $$self{'last_trade_time'}; |
166
|
0
|
|
|
|
|
0
|
$$self{'_string'} =~ m/(\xbc\xe8\xb0\xfa\xc3\xcd)(\d+:\d+) ([\d\,]+)/o; |
167
|
0
|
|
|
|
|
0
|
$self->_set_last_trade(); |
168
|
0
|
|
|
|
|
0
|
return $2; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _set_last_trade(){ |
172
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
173
|
1
|
|
|
|
|
3
|
$$self{'_string'} =~ m/(\xbc\xe8\xb0\xfa\xc3\xcd)(\d+:\d+) ([\d\,]+)/o; |
174
|
1
|
|
|
|
|
5
|
$$self{'last_trade_time'} = $2; |
175
|
1
|
|
|
|
|
4
|
$$self{'last_trade_price'} = $3; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub get_high_price(){ |
179
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
180
|
0
|
0
|
|
|
|
0
|
return $$self{'high_price'} if $$self{'high_price'}; |
181
|
0
|
|
|
|
|
0
|
$self->_set_high_price(); |
182
|
0
|
|
|
|
|
0
|
return $2; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _set_high_price(){ |
186
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
187
|
1
|
|
|
|
|
3
|
$$self{'_string'} =~ m/(\xb9\xe2\xc3\xcd)([\s\d\,]+)/o; |
188
|
1
|
|
|
|
|
3
|
$$self{'high_price'} = $2; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub get_low_price(){ |
192
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
193
|
0
|
0
|
|
|
|
0
|
return $$self{'low_price'} if $$self{'low_price'}; |
194
|
0
|
|
|
|
|
0
|
$self->_set_low_price(); |
195
|
0
|
|
|
|
|
0
|
return $2; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _set_low_price(){ |
199
|
1
|
|
|
1
|
|
1
|
my ($self) = @_; |
200
|
1
|
|
|
|
|
25
|
$$self{'_string'} =~ m/(\xb0\xc2\xc3\xcd)([\d\,]+)/o; |
201
|
1
|
|
|
|
|
4
|
$$self{'low_price'} = $2; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub get_prev_close(){ |
205
|
1
|
|
|
1
|
0
|
5
|
my ($self) = @_; |
206
|
1
|
50
|
|
|
|
3
|
return $$self{'prev_close'} if $$self{'prev_close'}; |
207
|
1
|
|
|
|
|
4
|
$self->_set_prev_close(); |
208
|
1
|
|
|
|
|
3
|
return $2; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub _set_prev_close(){ |
212
|
2
|
|
|
2
|
|
4
|
my ($self) = @_; |
213
|
2
|
|
|
|
|
4
|
$$self{'_string'} =~ m/(\xbd\xaa\xc3\xcd)([\d\,]+)/o; |
214
|
2
|
|
|
|
|
3
|
$$self{'prev_close'} = $2; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub get_volume(){ |
218
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
219
|
0
|
0
|
0
|
|
|
0
|
return $$self{'volume'} if scalar($$self{'volume'}) || scalar($$self{'volume'}) eq "0"; |
220
|
0
|
|
|
|
|
0
|
$self->_set_volume(); |
221
|
0
|
|
|
|
|
0
|
return $2; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub _set_volume(){ |
225
|
1
|
|
|
1
|
|
2
|
my ($self) = @_; |
226
|
1
|
|
|
|
|
2
|
$$self{'_string'} =~ m/(\xbd\xd0\xcd\xe8\xb9\xe2)([\d\,]+)/o; |
227
|
1
|
50
|
|
|
|
5
|
unless($2){ |
228
|
1
|
|
|
|
|
3
|
$$self{'volume'} = "0"; |
229
|
|
|
|
|
|
|
}else{ |
230
|
0
|
|
|
|
|
0
|
$$self{'volume'} = $2; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub get_change(){ |
235
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
236
|
0
|
0
|
0
|
|
|
0
|
return $$self{'change'} if scalar($$self{'change'}) || scalar($$self{'change'}) eq "0"; |
237
|
0
|
|
|
|
|
0
|
$self->_set_change(); |
238
|
0
|
|
|
|
|
0
|
return $2; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub _set_change(){ |
242
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
243
|
1
|
|
|
|
|
2
|
$$self{'_string'} =~ m/(\xc1\xb0\xc6\xfc\xc8\xe6)([\+\-][\d\,]+)/o; |
244
|
1
|
50
|
|
|
|
4
|
unless($2){ |
245
|
1
|
|
|
|
|
4
|
$$self{'change'} = "0"; |
246
|
|
|
|
|
|
|
}else{ |
247
|
0
|
|
|
|
|
|
$$self{'change'} = $2; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
1; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
__END__ |