blib/lib/Javascript/Select/Chain.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 93.3% 14 / 15 Podpod 11.1% 1 / 9 totaltotal 81.2% 78 / 96 CC 10 SCAR 7.3
CC
10
Cov
89%
validate
3.2
selectchain
3.0
quoteary
3.0
CRAP 2.1
« blib/lib/Javascript/Select/Chain/Nested.pm ↑ Summary blib/lib/Javascript/Select/make-manifest.pl »
1 package Javascript::Select::Chain;
2  
3 1 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 require Exporter;
11  
12 1 our @ISA = qw(Exporter);
13  
14 # Items to export into callers namespace by default. Note: do not export
15 # names by default without a very good reason. Use EXPORT_OK instead.
16 # Do not simply export all your public functions/methods/constants.
17  
18 # This allows declaration use Javascript::Select::Chain ':all';
19 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
20 # will save memory.
21 1 our %EXPORT_TAGS = ( 'all' => [ qw(
22
23 ) ],
24 );
25  
26 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ,
27 'selectchain'
28 );
29  
30 1 our @EXPORT = qw(
31
32 );
33  
34 1 our $VERSION = '1.3';
35  
36  
37 # Preloaded methods go here.
38  
39  
40 0 ▶sub header {
Subroutine header: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $fh = shift;
42 0 print $fh "var hide_empty_list=true;\n\n";
43 }
44  
45 1 ▶sub validate {
Subroutine validate: called CC=3 SCAR=11.7
Pod undocumented
46  
47 1 my $model = shift;
48  
49 exists $model->{listgroupname} or
50 1 ▶ confess "listgroupname must be supplied in model";
Branch: 1 branch
BranchTrueFalseTotal
exists $model->{"listgroupname"} or confess("listgroupname must be supplied in model") 1 0 1
51  
52 exists $model->{data} or
53 1 ▶ confess "data must be supplied in model";
Branch: 1 branch
BranchTrueFalseTotal
exists $model->{"data"} or confess("data must be supplied in model") 1 0 1
54  
55  
56 }
57  
58 1 ▶sub add_list_group {
Subroutine add_list_group: called CC=2 SCAR=7.0
Pod undocumented
59  
60 1 my ($fh, $model) = @_;
61  
62 1 ▶ $model->{data}[0][0][0] = "" unless defined($model->{data}[0][0][0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model->{"data"}[0][0][0] 0 1 1
63  
64 print $fh sprintf 'addListGroup("%s", "%s");',
65 $model->{listgroupname},
66 1 $model->{data}[0][0][0];
67  
68 1 print $fh "\n\n";
69 }
70  
71 102 ▶sub quoteary {
Subroutine quoteary: called CC=3 SCAR=11.1
Pod undocumented
72 102 my $ary = shift;
73 102 my $size = shift;
74  
75 102 for my $elt (0..$size-2) {
76 331 ▶ $ary->[$elt] = "" unless defined($ary->[$elt]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ary->[$elt] 0 331 331
77 331 $ary->[$elt] = sprintf '"%s"', $ary->[$elt];
78 }
79  
80 }
81  
82 1 my %quoteary = (addList => 5, addOption => 4);
83  
84 102 ▶sub addonelist {
Subroutine addonelist: called CC=1 SCAR=0.0
Pod undocumented
85  
86 102 my ($fh, $ary, $func) = @_;
87  
88 102 quoteary($ary, $quoteary{$func});
89  
90 102 print $fh sprintf "$func(%s);\n", join ', ', @$ary;
91 }
92  
93 3 ▶sub addlistary {
Subroutine addlistary: called CC=2 SCAR=6.9
Pod undocumented
94 3 my ($fh, $data, $func) = @_;
95  
96 3 for my $record (@$data) {
97 102 addonelist($fh,$record, $func);
98 }
99  
100 }
101  
102 1 ▶sub addlist {
Subroutine addlist: called CC=2 SCAR=6.9
Pod undocumented
103 1 my ($fh,$data) = @_;
104  
105  
106 1 for my $d (0 .. $#$data-1) {
107 2 addlistary($fh, $data->[$d], 'addList');
108 }
109  
110 }
111  
112 1 ▶sub addoption {
Subroutine addoption: called CC=1 SCAR=0.0
Pod undocumented
113 1 my ($fh,$data) = @_;
114  
115 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 # warn Dumper($data->[$#$data]);
117  
118 1 addlistary($fh, $data->[$#$data], 'addOption');
119  
120  
121 }
122  
123  
124  
125  
126 1 ▶sub selectchain {
Subroutine selectchain: called CC=3 SCAR=11.1
Pod documented
127 1 my ($model, $config) = @_;
128  
129 1 validate $model ;
130  
131 1 ▶ my $js = $config->{js} || "_out.js";
Condition50%1/2
$config->{'js'} || '_out.js'
l!l
10
MC/DC0%0/1
$config->{'js'} || '_out.js'
$config->{'js'}
Truth table50%1/2
A
A= $config->{'js'}
Aresult
11
00
132 1 my $jsf = new FileHandle;
133 1 ▶ $jsf->open("> $js") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$jsf->open("> $js") or die $! 1 0 1
134  
135 # header($jsf);
136 1 add_list_group($jsf, $model);
137  
138 1 addlist($jsf, $model->{data});
139 1 addoption($jsf, $model->{data});
140  
141 }
142  
143 1 1;
144 __END__
« blib/lib/Javascript/Select/Chain/Nested.pm ↑ Summary blib/lib/Javascript/Select/make-manifest.pl »