require
5.004;
use
vars
qw( $MORNINGSTAR_SE_FUNDS_URL)
;
our
$VERSION
=
'1.22'
;
sub
methods {
return
(
morningstar
=> \
&morningstar
); }
{
my
@labels
=
qw/date isodate method source name currency price/
;
sub
labels {
return
(
morningstar
=> \
@labels
); }
}
sub
morningstar {
my
$quoter
=
shift
;
my
@symbols
=
@_
;
return
unless
@symbols
;
my
(
$ua
,
$reply
,
$url
,
%funds
,
$te
,
$table
,
$row
,
@value_currency
,
$name
);
foreach
my
$symbol
(
@symbols
) {
$name
=
$symbol
;
$url
=
$MORNINGSTAR_SE_FUNDS_URL
;
$url
=
$url
.
$name
;
$ua
=
$quoter
->user_agent;
$reply
=
$ua
->request(GET
$url
);
unless
(
$reply
->is_success) {
foreach
my
$symbol
(
@symbols
) {
$funds
{
$symbol
,
"success"
} = 0;
$funds
{
$symbol
,
"errormsg"
} =
"HTTP failure"
;
}
return
wantarray
?
%funds
: \
%funds
;
}
$te
= new HTML::TableExtract();
$te
->parse(
$reply
->content);
my
$counter
= 0;
my
$dateset
= 0;
for
my
$table
(
$te
->tables()) {
for
my
$row
(
$table
->rows()) {
if
(
defined
(
@$row
[0])) {
if
(
'Senaste NAV'
eq
substr
(
@$row
[0],0,11)) {
@value_currency
=
split
(/ /,
$$row
[2]);
$funds
{
$name
,
'method'
} =
'morningstar_funds'
;
$funds
{
$name
,
'price'
} =
$value_currency
[0];
$funds
{
$name
,
'currency'
} =
$value_currency
[1];
$funds
{
$name
,
'success'
} = 1;
$funds
{
$name
,
'symbol'
} =
$name
;
$funds
{
$name
,
'source'
} =
'Finance::Quote::Morningstar'
;
$funds
{
$name
,
'name'
} =
$name
;
$funds
{
$name
,
'p_change'
} =
""
;
}
if
(
$counter
== 7 &&
$dateset
== 0) {
my
$date
=
substr
(
$$row
[1],0,10);
$quoter
->store_date(\
%funds
,
$name
, {
isodate
=>
$date
});
$dateset
= 1;
}
}
}
$counter
++;
}
foreach
my
$symbol
(
@symbols
) {
unless
(
$funds
{
$symbol
,
'success'
}) {
$funds
{
$symbol
,
"success"
} = 0;
$funds
{
$symbol
,
"errormsg"
} =
"Fund name not found"
;
}
}
}
return
%funds
if
wantarray
;
return
\
%funds
;
}
1;