<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Finance::Quote::PrudentialHK;
require 5.004;

use strict;

use vars qw($VERSION $PRUDENTIALHK_URL $PRUDENTIALHK_URL_SUFFIX);

use LWP::UserAgent;
use HTTP::Request::Common;

$VERSION = '1.18';
$PRUDENTIALHK_URL = 'http://www.prudential.com.hk/PruServlet?module=fund&amp;purpose=searchHistFund&amp;fundCd=';
$PRUDENTIALHK_URL_SUFFIX = '_U';

sub methods { return (prudentialhk =&gt; \&amp;prudentialhk); }

{
  my @labels = qw/date year month day method source name currency price/;

  sub labels { return (prudentialhk =&gt; \@labels); }
}

sub prudentialhk {
  my $quoter  = shift;
  my @symbols = @_;

  return unless @symbols;
  my ($ua, $reply, $url, %funds, $name);
  my (@decoded_html, $decoded_html, $price_date, $currency, $price, $date);

  foreach my $symbol (@symbols) {
    $name = $symbol;
    $url = $PRUDENTIALHK_URL;
    $url = $url . $name . $PRUDENTIALHK_URL_SUFFIX;
    $ua    = $quoter-&gt;user_agent;
    $reply = $ua-&gt;request(GET $url);
    unless ($reply-&gt;is_success) {
	  foreach my $symbol (@symbols) {
        $funds{$symbol, "success"}  = 0;
        $funds{$symbol, "errormsg"} = "HTTP failure";
	  }
	  return wantarray ? %funds : \%funds;
    }

    #my @decoded_html = split(/\n+/,Encode::decode_utf8($reply-&gt;content));
    my @decoded_html = split(/\n+/,$reply-&gt;content);
    my $decoded_html;
    
    while ($decoded_html = shift @decoded_html){
	    ($decoded_html =~ /fundPriceCell/) &amp;&amp; last;
    }

    #example: &lt;td align="center" class="fundPriceCell1"&gt;26/04/2013&lt;/td&gt;&lt;td align="center" class="fundPriceCell1"&gt;17.4430&lt;/td&gt;&lt;td align="center" class="fundPriceCell1"&gt;17.4430&lt;/td&gt;
    $price_date = $decoded_html;
                      
    $price_date =~ s/\&lt;td.*?\&gt;//g;
    ($date, $price) = split(/\&lt;\/td.*?\&gt;/, $price_date);

    #all products in Prudential HK are currently in USD only
    $currency = "USD";

    $funds{$name, 'method'}   = 'prudentialhk';
    $funds{$name, 'price'}    = $price;
    $funds{$name, 'currency'} = $currency;
    $funds{$name, 'success'}  = 1;
    $funds{$name, 'symbol'}  = $name;
    $funds{$name, 'source'}   = 'Finance::Quote::PrudentialHK';
    $funds{$name, 'name'}   = $name;
    $funds{$name, 'p_change'} = "";  # p_change is not retrieved (yet?)

    $date =~ /(\d\d?)\/(\d\d?)\/(\d\d\d?\d?)/;
    $quoter-&gt;store_date(\%funds, $name, {year =&gt; $3, month =&gt; $2, day =&gt; $1});
    

    # Check for undefined symbols
    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;


=head1 NAME

Finance::Quote::PrudentialHK - Obtain fund prices from Prudential HK

=head1 SYNOPSIS

    use Finance::Quote;

    $q = Finance::Quote-&gt;new;

    %fundinfo = $q-&gt;fetch("prudentialhk","Fund code");

=head1 DESCRIPTION

This module obtains information about Prudentail HK fund prices from
http://www.prudential.com.hk/PruServlet?module=fund&amp;purpose=searchHistFund&amp;fundCd=XXX_U
where XXX is the fund code (GGF, FEF, etc)

=head1 FUND CODE

You can get the Fund Code from the end of URL of the fund in Prudential page.

=head1 LABELS RETURNED

Information available may include the following labels:
date method source name currency price

=head1 SEE ALSO

www.prudential.com.hk

=head1 KNOWN BUGS

Doesn't work with Money USD Fund.

=cut
</pre></body></html>