blib/lib/YVDHOVE/List.pm

filter: Statementstmt 95.7% 68 / 71 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 85.9% 92 / 107 CC 12 SCAR 12.1
CC
12
Cov
88%
DelimitedListToHash
5.1
DelimitedListToArray
5.1
ArrayToDelimitedList
2.0
CRAP 3.3
↑ Summary
1 package YVDHOVE::List;
2  
3 1 ▶use 5.008000;
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 require Exporter;
8  
9 # ---------------------------------------------------------------------------------
10  
11 1 our @ISA = qw(Exporter);
12 1 our %EXPORT_TAGS = ( 'all' => [ qw( ArrayToDelimitedList
13 HashToDelimitedList
14 DelimitedListToArray
15 DelimitedListToHash
16 DelimitedKeyValuePairToHash ) ] );
17 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} });
18 1 our @EXPORT = ();
19  
20 1 our $VERSION = '1.03';
21  
22 # ---------------------------------------------------------------------------------
23  
24 1 ▶sub ArrayToDelimitedList($$$) {
Subroutine ArrayToDelimitedList: called CC=2 SCAR=7.1
Pod documented
25
26 1 my ($myArrayRef, $delimiter, $debug) = @_;
27
28 1 my $list = '';
29
30 1 ▶ if( @$myArrayRef ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$myArrayRef) { } 1 0 1
31 1 @$myArrayRef = sort(@$myArrayRef);
32 1 $list = join($delimiter, @$myArrayRef);
33 } else {
34 0 $list = '';
35 }
36  
37 1 return $list;
38 }
39  
40 # ---------------------------------------------------------------------------------
41  
42 1 ▶sub HashToDelimitedList($$$) {
Subroutine HashToDelimitedList: called CC=2 SCAR=6.9
Pod documented
43
44 1 my ($myHASH, $delimiter, $debug) = @_;
45
46 1 my $list = '';
47
48 1 for my $key ( sort keys %$myHASH ) {
49 4 $list .= $key . $delimiter;
50 }
51
52 1 chop($list);
53
54 1 return $list;
55 }
56  
57 # ---------------------------------------------------------------------------------
58  
59 2 ▶sub DelimitedListToArray($$$$) {
Subroutine DelimitedListToArray: called CC=5 SCAR=16.2
Pod documented
60
61 2 my ($myList, $delimiter, $count, $debug) = @_;
62
63 2 my @myArray = ();
64
65 2 ▶ if (defined $myList && $myList ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $myList and $myList ne "") 2 0 2
Condition33%1/3
defined $myList and $myList ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $myList and $myList ne ""
defined $myList $myList ne ""
Truth table33%1/3
A and B
A= defined $myListB= $myList ne ""
ABresult
0X0
100
111
66 2 my @items = split(/$delimiter/, $myList);
67 2 my $number = 0; my $value = '';
68 2 foreach my $item (@items) {
69 8 $value .= $item . $delimiter;
70 8 $number++;
71 8 ▶ if ($number == $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number == $count) 6 2 8
72 6 chop($value);
73 6 push( @myArray, $value );
74 6 $value = ''; $number = 0;
75 }
76 }
77 2 @myArray = sort(@myArray);
78 }
79  
80 2 return \@myArray;
81 }
82  
83 # ---------------------------------------------------------------------------------
84  
85 2 ▶sub DelimitedListToHash($$$$) {
Subroutine DelimitedListToHash: called CC=5 SCAR=16.2
Pod documented
86
87 2 my ($myList, $delimiter, $count, $debug) = @_;
88 2 ▶ my @items = split (/$delimiter/, $myList) if (defined $myList && $myList ne '');
Branch: 1 branch
BranchTrueFalseTotal
if defined $myList and $myList ne "" 2 0 2
Condition33%1/3
defined $myList and $myList ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $myList and $myList ne ""
defined $myList $myList ne ""
Truth table33%1/3
A and B
A= defined $myListB= $myList ne ""
ABresult
0X0
100
111
89 2 my $number = 0; my $key = '';
90 2 my %myHASH = ();
91  
92 2 foreach my $item (@items) {
93 8 $key .= $item . $delimiter;
94 8 $number++;
95
96 8 ▶ if ($number == $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number == $count) 6 2 8
97 6 chop $key;
98 6 $myHASH{$key} = undef;
99 6 $key = '';
100 6 $number = 0;
101 }
102 }
103
104 2 return \%myHASH;
105 }
106  
107 # ---------------------------------------------------------------------------------
108  
109 1 ▶sub DelimitedKeyValuePairToHash($$$) {
Subroutine DelimitedKeyValuePairToHash: called CC=2 SCAR=7.1
Pod documented
110
111 1 my ($myList, $delimiter, $debug) = @_;
112
113 1 ▶ use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 my %myHASH;
115 1 tie(%myHASH, 'Tie::IxHash');
116 1 %myHASH = map { my ($key, $value) = split (/=/) } split (/$delimiter/, $myList);
117
118 1 ▶ if($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 1 1
119 0 print "Delimited List: " . $myList . "\n";
120 0 print "Size of myHASH: " . keys( %myHASH ) . "</p>\n";
121 }
122
123 1 return \%myHASH;
124 }
125  
126 # ---------------------------------------------------------------------------------
127  
128 1 1;
129  
130 # ---------------------------------------------------------------------------------
131 __END__
↑ Summary