GeniusTrader/DB.pm

filter: Statementstmt 21.4% 6 / 28 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 25.0% 1 / 4 Podpod 33.3% 1 / 3 totaltotal 13.1% 8 / 61 CC 12 SCAR 43.3
CC
12
Cov
12%
get_name
110.0
has_code
12.0
get_db_name
2.0
CRAP 75.9
« GeniusTrader/Graphics/Object/Candle.pm ↑ Summary GeniusTrader/BackTest.pm »
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
BranchTrueFalseTotal
if (defined $name and $name ne '') { } 0 0 0
Condition0%0/3
defined $name and $name ne ""
!ll&&!rl&&r
000
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 ""
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if defined $name and $name 0 0 0
Condition0%0/3
defined $name and $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and $name
defined $name $name
Truth table0%0/3
A and B
A= defined $nameB= $name
ABresult
0X0
100
111
55  
56 0 ▶ if (! $loaded_sharenames) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Finance::GeniusTrader::DB::loaded_sharenames) 0 0 0
57 0 my $file = Finance::GeniusTrader::Conf::_get_home_path()."/.gt/sharenames";
58 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
59 0 ▶ open(NAMES, "<", "$file") || die "Can't open $file : $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open NAMES, "<", "$file" or die "Can't open $file : $!\n" 0 0 0
60 0 foreach (<NAMES>) {
61 0 chomp;
62 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
63 0 my ($c, $d) = split /\t/;
64 0 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 0 0 0
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
BranchTrueFalseTotal
exists $Finance::GeniusTrader::DB::sharenames{$code} ? : 0 0 0
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;
« GeniusTrader/Graphics/Object/Candle.pm ↑ Summary GeniusTrader/BackTest.pm »