| 1 | package Finance::GeniusTrader::DB; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Copyright 2000-2004 Raphaƫl Hertzog, Fabien Fulhaber | ||||||||||||||||||||||||||||
| 4 | # This file is distributed under the terms of the General Public License | ||||||||||||||||||||||||||||
| 5 | # version 2 or (at your option) any later version. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $loaded_sharenames = 0; | |||||||||||||||||||||||||||
| 10 | 1 | our %sharenames; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Finance::GeniusTrader::DB - Database to retrieve (an history of) prices of various shares | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | No documentation available. Look at the DB::* modules for | ||||||||||||||||||||||||||||
| 19 | real exemples. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub has_code { | ||||||||||||||||||||||||||
|
Subroutine
has_code: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $code) = @_; | |||||||||||||||||||||||||||
| 25 | # Default implementation is a kludge. | ||||||||||||||||||||||||||||
| 26 | # We have no way to know if the underlying database has the code | ||||||||||||||||||||||||||||
| 27 | # without trying to retrieve the prices | ||||||||||||||||||||||||||||
| 28 | 0 | my $name = $self->get_name($code); | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if (defined($name) && $name ne "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and $name ne ""
MC/DC0%0/2
defined $name and $name ne ""
defined $name
$name ne ""
Truth table0%0/3
A and B
A= defined $nameB= $name ne ""
| |||||||||||||||||||||||||||||
| 30 | 0 | return 1; | |||||||||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||||||||
| 32 | 0 | return 0; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =over | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item C<< get_name ($code) >> | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Returns the long name of the market (if defined). | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | See also ~/.gt/sharenames which contains lines of the form | ||||||||||||||||||||||||||||
| 43 | <code>\t<long name> | ||||||||||||||||||||||||||||
| 44 | mapping a market code to its long name. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =back | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub get_name { | ||||||||||||||||||||||||||
|
Subroutine
get_name: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($self, $code) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $name = $self->get_db_name($code); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | return $name if (defined($name) && $name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and $name
MC/DC0%0/2
defined $name and $name
defined $name
$name
Truth table0%0/3
A and B
A= defined $nameB= $name
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (! $loaded_sharenames) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | my $file = Finance::GeniusTrader::Conf::_get_home_path()."/.gt/sharenames"; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (-e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | open(NAMES, "<", "$file") || die "Can't open $file : $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | foreach (<NAMES>) { | |||||||||||||||||||||||||||
| 61 | 0 | chomp; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | next unless $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($c, $d) = split /\t/; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($c) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $sharenames{$c} = $d; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | close NAMES; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | $loaded_sharenames = 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | ( exists $sharenames{$code} ) | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | ? return $sharenames{$code} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | : return ""; | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub get_db_name { | ||||||||||||||||||||||||||
|
Subroutine
get_db_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 0 | return undef; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||||||||||