blib/lib/Data/Stag/Util.pm

filter: Statementstmt 92.6% 38 / 41 Branchbran 70.0% 7 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 88.8% 56 / 63 CC 8 SCAR 17.1
CC
8
Cov
89%
rearrange
8.3
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
« blib/script/stag-drawtree.pl ↑ Summary blib/lib/Data/Stag/StagDB.pm »
1 package Data::Stag::Util;
2  
3 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 20 ▶use vars qw(@EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 $VERSION="0.14";
10  
11 20 @EXPORT_OK = qw(rearrange);
12 20 %EXPORT_TAGS = (all => [@EXPORT_OK]);
13  
14 172 ▶sub rearrange {
Subroutine rearrange: called CC=8 SCAR=21.2
Pod undocumented
15 172 my($order,@param) = @_;
16  
17 # If there are no parameters, we simply wish to return
18 # an undef array which is the size of the @{$order} array.
19 0 ▶ return (undef) x $#{$order} unless @param;
Branch: 1 branch
BranchTrueFalseTotal
unless @param 0 172 172
20  
21 # If we've got parameters, we need to check to see whether
22 # they are named or simply listed. If they are listed, we
23 # can just return them.
24 172 ▶ return @param unless (defined($param[0]) && $param[0]=~/^-\S/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param[0] and $param[0] =~ /^-\S/ 60 112 172
Condition100%3/3
defined $param[0] and $param[0] =~ /^-\S/
!ll&&!rl&&r
3822112
MC/DC100%2/2
defined $param[0] and $param[0] =~ /^-\S/
defined $param[0] $param[0] =~ /^-\S/
Truth table100%3/3
A and B
A= defined $param[0]B= $param[0] =~ /^-\S/
ABresult
0X0
100
111
25  
26 # Now we've got to do some work on the named parameters.
27 # The next few lines strip out the '-' characters which
28 # preceed the keys, and capitalizes them.
29 112 my $i;
30 112 ▶ for ($i=0;$i<@param;$i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @param) 231 112 343
31 231 ▶ if (!defined($param[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $param[$i]) { } 0 231 231
32 0 cluck("Hmmm in $i ".CORE::join(";", @param)." == ".CORE::join(";",@$order)."\n");
33 }
34 else {
35 231 $param[$i]=~s/^\-//;
36 231 $param[$i]=~tr/a-z/A-Z/;
37 }
38 }
39
40 # Now we'll convert the @params variable into an associative array.
41 112 my(%param) = @param;
42  
43 112 my(@return_array);
44
45 # What we intend to do is loop through the @{$order} variable,
46 # and for each value, we use that as a key into our associative
47 # array, pushing the value at that key onto our return array.
48 my($key);
49  
50 112 foreach $key (@{$order}) {
51 339 $key=~tr/a-z/A-Z/;
52 339 my($value) = $param{$key};
53 339 delete $param{$key};
54 339 push(@return_array,$value);
55 }
56
57 # catch user misspellings resulting in unrecognized names
58 112 my(@restkeys) = keys %param;
59 112 ▶ if (scalar(@restkeys) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @restkeys > 0) 0 112 112
60 0 carp("@restkeys not processed in rearrange(), did you use a
61 non-recognized parameter name ? ");
62 }
63 112 return @return_array;
64 }
65  
66  
67 20 1;
68  
« blib/script/stag-drawtree.pl ↑ Summary blib/lib/Data/Stag/StagDB.pm »