App/Chart/IndicatorInfo.pm

filter: Statementstmt 43.1% 57 / 132 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 62.0% 18 / 29 Podpod 0.0% 0 / 6 totaltotal 34.5% 75 / 217 CC 21 SCAR 25.0
CC
21
Cov
33%
parameter_info
42.0
new
30.0
parameter_info
13.3
CRAP 12.2
« App/Chart/Gtk2/PreferencesDialog.pm ↑ Summary App/Chart/Finance/Yahoo/Exchanges.pm »
1 # Copyright 2009, 2024 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::IndicatorInfo;
18 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Locale::TextDomain ('App-Chart');
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
26 0 my ($class, $key) = @_;
27 0 if (DEBUG) { print "IndicatorInfo $key\n"; }
28 0 ▶ if ($key && $key =~ /^(GT|TA)_/p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key and $key =~ /^(GT|TA)_/p) 0 0 0
Condition0%0/3
$key and $key =~ /^(GT|TA)_/p
!ll&&!rl&&r
000
MC/DC0%0/2
$key and $key =~ /^(GT|TA)_/p
$key $key =~ /^(GT|TA)_/p
Truth table0%0/3
A and B
A= $keyB= $key =~ /^(GT|TA)_/p
ABresult
0X0
100
111
29 0 $key = ${^POSTMATCH};
30 0 $class = "App::Chart::IndicatorInfo::$1";
31 }
32 0 ▶ if ($key && $key eq 'None') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key and $key eq "None") 0 0 0
Condition0%0/3
$key and $key eq "None"
!ll&&!rl&&r
000
MC/DC0%0/2
$key and $key eq "None"
$key $key eq "None"
Truth table0%0/3
A and B
A= $keyB= $key eq "None"
ABresult
0X0
100
111
33 0 $key = undef;
34 }
35 0 return bless { key => $key }, $class;
36 }
37  
38 0 ▶sub manual {
Subroutine manual: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my ($self) = @_;
40 0 ▶ my $func = $self->module_func('manual') || return undef;
Condition0%0/2
$self->module_func('manual') || (return undef)
l!l
00
MC/DC0%0/1
$self->module_func('manual') || (return undef)
$self->module_func('manual')
Truth table0%0/2
A
A= $self->module_func('manual')
Aresult
11
00
41 0 return $func->();
42 }
43 0 ▶sub parameter_info {
Subroutine parameter_info: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($self) = @_;
45 0 ▶ my $func = $self->module_func('parameter_info') || return [];
Condition0%0/2
$self->module_func('parameter_info') || (return [])
l!l
00
MC/DC0%0/1
$self->module_func('parameter_info') || (return [])
$self->module_func('parameter_info')
Truth table0%0/2
A
A= $self->module_func('parameter_info')
Aresult
11
00
46 0 return $func->();
47 }
48  
49 0 ▶sub module_func {
Subroutine module_func: not called CC=2 SCAR=17.9
Pod undocumented
50 0 my ($self, $funcname) = @_;
51 0 ▶ my $module = $self->module_load || return;
Condition0%0/2
$self->module_load || (return)
l!l
00
MC/DC0%0/1
$self->module_load || (return)
$self->module_load
Truth table0%0/2
A
A= $self->module_load
Aresult
11
00
52 0 return $module->can($funcname);
53 }
54 1 my %warned;
55 0 ▶sub module_load {
Subroutine module_load: not called CC=3 SCAR=24.8
Pod undocumented
56 0 my ($self) = @_;
57 0 my $module = $self->module;
58 0 require Module::Load;
59 0 ▶ if (! eval { Module::Load::load($module); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &Module::Load::load($module); 1 } }) 0 0 0
60 0 print "module_load(): Cannot load $module\n";
61 0 ▶ $warned{$module} ||= do { warn "Cannot load $module: $@"; 1 };
Condition0%0/3
$warned{$module} ||= do { warn "Cannot load ${module}: $@"; 1 }
l!l&&r!l&&!r
000
MC/DC0%0/2
$warned{$module} ||= do { warn "Cannot load ${module}: $@"; 1 }
$warned{$module} do { warn "Cannot load ${module}: $@"; 1 }
Truth table0%0/3
A ||= B
A= $warned{$module}B= do { warn "Cannot load ${module}: $@"; 1 }
ABresult
1X1
011
000
62 0 return undef;
63 }
64 0 return $module;
65 }
66 0 ▶sub module {
Subroutine module: not called CC=2 SCAR=17.9
Pod undocumented
67 0 my ($self) = @_;
68 0 ▶ return ($self->{'key'} && "App::Chart::Series::Derived::$self->{'key'}");
Condition0%0/2
$self->{'key'} && "App::Chart::Series::Derived::$self->{'key'}"
!ll
00
MC/DC0%0/1
$self->{'key'} && "App::Chart::Series::Derived::$self->{'key'}"
$self->{'key'}
Truth table0%0/2
A
A= $self->{'key'}
Aresult
00
11
69 }
70  
71 #------------------------------------------------------------------------------
72 package App::Chart::IndicatorInfo::GT;
73 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 ▶use Locale::TextDomain ('App-Chart');
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 our @ISA = ('App::Chart::IndicatorInfo');
77  
78 # ENHANCE-ME: @DEFAULT_ARGS shows when OHLCV needed ...
79  
80 1 ▶use constant manual => __p('manual-node','Other Indicator Packages');
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 0 ▶sub parameter_info {
Subroutine parameter_info: not called CC=4 SCAR=25.8
83 0 my ($self) = @_;
84 0 ▶ my $module = $self->module_load || return;
Condition0%0/2
$self->module_load || (return)
l!l
00
MC/DC0%0/1
$self->module_load || (return)
$self->module_load
Truth table0%0/2
A
A= $self->module_load
Aresult
11
00
85 0 ▶ my @default_args = do { no strict 'refs'; @{"${module}::DEFAULT_ARGS"} };
Subroutine BEGIN: called CC=1 SCAR=1.2
86 0 my @ret;
87 0 foreach my $arg (@default_args) {
88 0 ▶ if (Scalar::Util::looks_like_number ($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($arg)) 0 0 0
89 0 my $i = @ret;
90 0 push @ret, { name => "Arg$i",
91 key => "GT-arg$i",
92 default => $default_args[$i],
93 };
94 }
95 }
96 0 return \@ret;
97 }
98  
99 0 ▶sub module {
Subroutine module: not called CC=1 SCAR=6.9
100 0 my ($self) = @_;
101 0 return 'GT::Indicators::' . $self->{'key'};
102 }
103  
104 #------------------------------------------------------------------------------
105 package App::Chart::IndicatorInfo::TA;
106 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 1 ▶use Locale::TextDomain ('App-Chart');
Subroutine BEGIN: called CC=1 SCAR=0.0
109 1 our @ISA = ('App::Chart::IndicatorInfo');
110  
111 1 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
112  
113 1 ▶use constant { manual => __p('manual-node','Other Indicator Packages'),
Subroutine BEGIN: called CC=1 SCAR=0.0
114 module => 'Finance::TA',
115 1 };
116  
117 0 ▶sub parameter_info {
Subroutine parameter_info: not called CC=6 SCAR=37.4
118 0 my ($self) = @_;
119 0 ▶ $self->module_load || return [];
Branch: 1 branch
BranchTrueFalseTotal
$self->module_load or return [] 0 0 0
120 0 my @ret;
121  
122 0 my $func = $self->{'key'};
123 0 my ($fh, $fi) = _funcbits ($self);
124 0 foreach my $i (0 .. $fi->{'nbOptInput'} - 1) {
125 0 my ($info, $retcode);
126 0 ▶ ($retcode = Finance::TA::TA_GetOptInputParameterInfo ($fh, $i, \$info))
Branch: 1 branch
BranchTrueFalseTotal
($retcode = Finance::TA::TA_GetOptInputParameterInfo($fh, $i, \$info)) == $Finance::TA::TA_SUCCESS or die "Function $func parameter $i ", _retcode_str($retcode) 0 0 0
127 == $Finance::TA::TA_SUCCESS
128 or die "Function $func parameter $i ",_retcode_str ($retcode);
129  
130 my $elem = { key => "TA_${func}_$info->{'paramName'}",
131 name => $info->{'displayName'},
132 0 default => $info->{'defaultValue'},
133 type => 'integer',
134 };
135 0 push @ret, $elem;
136  
137 0 my $dataset = $info->{'dataSet'};
138 0 if (DEBUG) { print "dataSet $dataset\n"; }
139  
140 0 ▶ if ($info->{'type'} == $Finance::TA::TA_OptInput_RealRange) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"type"} == $Finance::TA::TA_OptInput_RealRange) 0 0 0
141 0 $elem->{'type'} = 'float';
142 }
143  
144 # TA_IntegerRange and TA_RealRange
145 {
146 ## no critic (RequireCheckingReturnValueOfEval)
147 0 eval {
148 0 $elem->{'minimum'} = $dataset->{'min'};
149 };
150 0 eval {
151 # dummy 100_000 for no maximum
152 0 ▶ if ((my $max = $dataset->{'max'}) != 100_000) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $max = $dataset->{"max"}) != 100000) 0 0 0
153 0 $elem->{'maximum'} = $max;
154 }
155 };
156 # TA_RealRange
157 0 eval {
158 0 $elem->{'decimals'} = $dataset->{'precision'};
159 };
160 }
161  
162 # TA_RealRange and TA_IntegerRange 'suggested_increment',
163 # 'suggested_start', 'suggested_end' are meant for mechanical searching
164 # rather than user controls ...
165  
166 # TA_OPTIN_IS_PERCENT
167 # TA_OPTIN_IS_DEGREE angle
168 # TA_OPTIN_IS_CURRENCY
169 # TA_OPTIN_ADVANCED
170 }
171 0 return \@ret;
172 }
173  
174 0 ▶sub _funcbits {
Subroutine _funcbits: not called CC=3 SCAR=24.8
175 0 my ($self) = @_;
176 0 my ($fh, $fi, $retcode);
177 0 ▶ ($retcode = Finance::TA::TA_GetFuncHandle ($self->{'key'}, \$fh))
Branch: 1 branch
BranchTrueFalseTotal
($retcode = Finance::TA::TA_GetFuncHandle($self->{"key"}, \$fh)) == $Finance::TA::TA_SUCCESS or die qq[FuncHandle $self->{"key"} ], _retcode_str($retcode) 0 0 0
178 == $Finance::TA::TA_SUCCESS
179 or die "FuncHandle $self->{'key'} ",_retcode_str ($retcode);
180  
181 0 ▶ ($retcode = Finance::TA::TA_GetFuncInfo ($fh, \$fi))
Branch: 1 branch
BranchTrueFalseTotal
($retcode = Finance::TA::TA_GetFuncInfo($fh, \$fi)) == $Finance::TA::TA_SUCCESS or die qq[FuncInfo $self->{"key"} ], _retcode_str($retcode) 0 0 0
182 == $Finance::TA::TA_SUCCESS
183 or die "FuncInfo $self->{'key'} ",_retcode_str ($retcode);
184  
185 0 return ($fh, $fi);
186 }
187 0 ▶sub _retcode_str {
Subroutine _retcode_str: not called CC=1 SCAR=6.9
188 0 my ($retcode) = @_;
189 0 my $rci = Finance::TA::TA_RetCodeInfo->new ($retcode);
190 0 return "[$rci->{'enumStr'}] $rci->{'infoStr'}";
191 }
192  
193 #------------------------------------------------------------------------------
194 package App::Chart::IndicatorInfo::Undef;
195 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
196 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
197  
198 use constant
199 1 ▶ { manual => undef,
Subroutine BEGIN: called CC=1 SCAR=0.0
200 parameter_info => [],
201 1 };
202  
203 1 1;
204 __END__
« App/Chart/Gtk2/PreferencesDialog.pm ↑ Summary App/Chart/Finance/Yahoo/Exchanges.pm »