blib/lib/Text/NumericData/App/txdconstruct.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 55.0% 11 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 83.1% 69 / 83 SCAR 25.3
CC
12
Cov
85%
main
13.6
BEGIN
1.0
BEGIN
1.0
CRAP 12.5
« blib/lib/Text/NumericData/App/txdsort.pm ↑ Summary blib/lib/Text/NumericData/App/txdfromafors.pm »
1 package Text::NumericData::App::txdconstruct;
2  
3 5 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Text::NumericData;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Text::NumericData::Calc qw(formula_function);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Text::NumericData::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # This is just a placeholder because of a past build system bug.
11 # The one and only version for Text::NumericData is kept in
12 # the Text::NumericData module itself.
13 5 our $VERSION = '1';
14 5 $VERSION = eval $VERSION;
15  
16 #the infostring says it all
17 5 my $infostring = 'text data construction
18  
19 I will produce some TextData following the formula you give me. Syntax is like that of txdcalc with only the STDOUT data; which means: You access the current data set via variables [1].. [x] (or [0,1]..[0,x] if you really want) and the global arrays A and C via A0..Ax and C0..Cx. You can initialze A and are encouraged to work with that array for custom operations. C has at the moment the only function to provide the data set number with C0 (set it to -1 to stop).
20 A data set is printed to STDOUT only when there is actually some data - so you can check for a condition in the formula and end the construction without creating a last futile line. You can, though, enable easy recursive calculation by initializing the data array (via --data parameter) in which case the data fields will always hold their last values when entering the formula.
21  
22 Variables: A is for you, C is special: C0 is used for the data set number, C1 for the number of data sets to create, C2 for (C0-1)/(C1-1); (and maybe other stat stuff in C following in future...)
23  
24 The formula can also be given as stand-alone command line argument (this overrides the other setting).
25  
26 Example:
27  
28 txdconstruct -n=200 -i="0,1/3" "[1] += 1; [2] = 4*[2]*(1-[2]);"
29  
30 gives a trajectory (some steps of iteration) for the logistic map.';
31  
32 5 our @ISA = ('Text::NumericData::App');
33  
34 sub new
35 {
36 6 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
37 6 my @pars =
38 (
39 # 'header','','H','use this header (\n becomes an appropriate line end, end of string by itself)',
40 'formula','[1] = C0','f','specify formula here'
41 ,'vars','','v','initialize the additional variable array A (comma-separeted for eval)'
42 ,'debug',0,'D','give some info that may help debugging'
43 ,'number',10,'n','number of datasets to create (when < 0: until _you_ set C0 to -1)'
44 ,'init','','i','initialize data - comma-separated for eval... this enables easy recursive calculations by always preserving the last values'
45 ,'plainperl',0,'',
46 'Use plain Perl syntax for formula for full force without confusing the intermediate parser.'
47 );
48  
49 6 return $class->SUPER::new
50 ({
51 parconf=>{ info=>$infostring # default version
52 # default author
53 # default copyright
54 }, pardef=>\@pars});
55 }
56  
57 sub main
58 {
59 7 ▶ my $self = shift;
Subroutine main: called CC=12 SCAR=26.1
Pod undocumented
60 7 my $param = $self->{param};
61 7 my $out = $self->{out};
62 7 my $txd = Text::NumericData->new($self->{param});
63 7 ▶ if(@{$self->{argv}}){ $param->{formula} = shift(@{$self->{argv}}); }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"argv"};}) 7 0 7
64 my $ff = formula_function( $param->{formula},
65 {
66 verbose=>$param->{debug}
67 , plainperl=>$param->{plainperl}
68 7 } );
69 7 ▶ die "Cannot parse your formula, try --debug\n" unless defined $ff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ff 0 7 7
70  
71 7 my @C = (0, $param->{number}, 0);
72 7 my @A = eval '('.$param->{vars}.')';
73  
74 # Dangerous ... change that!
75 7 my $odata = eval '[('.$param->{init}.')]';
76 7 ▶ my $recursive = @{$odata} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$odata;} ? : 0 7 7
77  
78 7 ▶ print $out ${$txd->data_line($odata)} if $recursive;
Branch: 1 branch
BranchTrueFalseTotal
if $recursive 0 7 7
79  
80 7 ▶ while(++$C[0] and $param->{number} >= 0 ? $C[0] <= $param->{number} : 1)
Branch: 2 branches
BranchTrueFalseTotal
if (++$C[0] and $param->{"number"} >= 0 ? $C[0] <= $param->{"number"} : 1) 242 7 249
$param->{'number'} >= 0 ? : 249 0 249
Condition66%2/3
++$C[0] and $param->{"number"} >= 0 ? $C[0] <= $param->{"number"} : 1
!ll&&!rl&&r
07242
MC/DC50%1/2
++$C[0] and $param->{"number"} >= 0 ? $C[0] <= $param->{"number"} : 1
++$C[0] $param->{"number"} >= 0 ? $C[0] <= $param->{"number"} : 1
Truth table66%2/3
A and B
A= ++$C[0]B= $param->{"number"} >= 0 ? $C[0] <= $param->{"number"} : 1
ABresult
0X0
100
111
81 {
82 242 ▶ my @data = $recursive ? ($odata) : ([]);
Branch: 1 branch
BranchTrueFalseTotal
$recursive ? : 0 242 242
83 242 ▶ $C[2] = $C[1] > 1 ? ($C[0]-1)/($C[1]-1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$C[1] > 1 ? : 242 0 242
84 242 &$ff(\@data,\@A,\@C);
85 242 ▶ print $out ${$txd->data_line($data[0])} if @{$data[0]};
Branch: 1 branch
BranchTrueFalseTotal
if @{$data[0];} 242 0 242
86 242 ▶ $odata = $data[0] if $recursive;
Branch: 1 branch
BranchTrueFalseTotal
if $recursive 0 242 242
87 }
88  
89 7 return 0;
90 }
91  
92 5 1;
93  
« blib/lib/Text/NumericData/App/txdsort.pm ↑ Summary blib/lib/Text/NumericData/App/txdfromafors.pm »