App/Chart/FinanceQuote.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 79 CC 2 SCAR 9.6
CC
2
Cov
0%
latest_download
6.0
setup
2.0
BEGIN
2.0
CRAP 2.6
1 # Copyright 2008, 2009, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::FinanceQuote;
18 use strict;
19 use warnings;
20 use Carp;
21 use Locale::TextDomain 'App-Chart';
22 use App::Chart::Download;
23 use App::Chart::LatestHandler;
24  
25 use constant DEBUG => 0;
26  
27 sub setup {
28 my ($class, %options) = @_;
29 my $modules = delete $options{'modules'} or croak;
30 my $method = delete $options{'method'} or croak;
31 my $suffix = delete $options{'suffix'} or croak;
32 my $pred = delete $options{'pred'}
33 || App::Chart::Sympred::Suffix->new ($suffix);
34 App::Chart::LatestHandler->new
35 (pred => $pred,
36 proc => sub { latest_download ($modules, $method, $suffix, @_) },
37 %options);
38 }
39  
40 sub latest_download {
41 my ($modules, $method, $suffix, $symbol_list) = @_;
42  
43 if (DEBUG) { require Data::Dumper;
44 print Data::Dumper::Dumper($modules); }
45  
46 # lose .FQ
47 $symbol_list = [ map {App::Chart::symbol_sans_suffix($_)} @$symbol_list ];
48  
49 App::Chart::Download::status
50 (__x('FinanceQuote {method} {symbol_range}',
51 method => $method,
52 symbol_range =>
53 App::Chart::Download::symbol_range_string ($symbol_list)));
54 require Finance::Quote;
55 my $q = Finance::Quote->new (@$modules);
56 my $quotes = $q->fetch ($method, @$symbol_list);
57  
58 require App::Chart::Suffix::FQ;
59 my $h = App::Chart::Suffix::FQ::quotes_to_group
60 ($suffix, $symbol_list, $quotes);
61 App::Chart::Download::write_latest_group ($h);
62 }
63  
64 1;
65 __END__