| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $param[0] and $param[0] =~ /^-\S/
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/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | 231 | ▶ | if (!defined($param[$i])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||