1package Finance::QuoteTW::Franklin;
2use Spiffy -Base;
3use WWW::Mechanize;
4use HTML::TableExtract;
5use Encode qw/from_to/;
6use Encode::TW;
7use HTML::Encoding 'encoding_from_http_message';
8
9#---------------------------------------------------------------------------
10#  Variables
11#---------------------------------------------------------------------------
12
13use version; our $VERSION = qv('0.04');
14
15#---------------------------------------------------------------------------
16#  Methods
17#---------------------------------------------------------------------------
18
19sub fetch {
20	my $b = WWW::Mechanize->new;
21	my $response = $b->get('http://www.franklin.com.tw/1.FundIntro/1.3FundNet.asp');
22	my $current_encoding = encoding_from_http_message($response);
23	my $date = $1 if $b->content =~ /(\d+\/\d+\/\d+)/;
24
25	my $te = HTML::TableExtract->new(depth => 3);
26	$te->parse($b->content);
27	my @result;
28	my @ts = $te->tables;
29	foreach my $index (0..2) {
30		my @rows = $ts[$index]->rows;
31		shift @rows;
32
33		foreach my $row (@rows) {
34			next unless $row->[3] =~ /\d+\.\d+/;
35			my @data = map { s/\s+//g if defined $_; $_ } @$row;
36			from_to($data[0], $current_encoding, $self->{encoding});
37			$data[5] =~ s/\+//;
38			$data[5] =~ s/^-$/0/;
39
40			push @result, {
41				name     => $data[0],
42				date     => $date,
43				nav      => $data[3],
44				change   => $data[5],
45				currency => $data[2],
46				type     => $data[1],
47			};
48		}
49	}
50
51	return @result;
52}
53
54__END__
55
56=head1 NAME
57
58Finance::QuoteTW::Franklin - Get fund quotes from www.franklin.com.tw
59
60=head1 SYNOPSIS
61
62See L<Finance::QuoteTW>.
63
64=head1 DESCRIPTION
65
66Get fund quotes from www.franklin.com.tw
67
68=head1 FUNCTIONS
69
70=head2 fetch
71
72see L<Finance::QuoteTW>
73
74=head1 AUTHOR
75
76Alec Chen <alec@cpan.org>
77
78=head1 COPYRIGHT
79
80Copyright (C) 2007 by Alec Chen. All rights reserved.
81
82This library is free software; you can redistribute it and/or modify
83it under the same terms as Perl itself, either Perl version 5.8.8 or,
84at your option, any later version of Perl 5 you may have available.
85
86=cut
87
88