File Coverage

blib/lib/Data/Stag/Util.pm
Criterion Covered Total %
statement 34 37 91.8
branch 5 8 62.5
condition 3 3 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 48 55 87.2


line stmt bran cond sub pod time code
1             package Data::Stag::Util;
2              
3 20     20   107 use Carp;
  20         35  
  20         1235  
4 20     20   106 use strict;
  20         35  
  20         632  
5 20     20   101 use vars qw(@EXPORT_OK %EXPORT_TAGS);
  20         34  
  20         1022  
6 20     20   107 use base qw(Exporter);
  20         43  
  20         2100  
7              
8 20     20   108 use vars qw($VERSION);
  20         34  
  20         14323  
9             $VERSION="0.14";
10              
11             @EXPORT_OK = qw(rearrange);
12             %EXPORT_TAGS = (all => [@EXPORT_OK]);
13              
14             sub rearrange {
15 172     172 0 517 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 172 50       514 return (undef) x $#{$order} unless @param;
  0         0  
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 100 100     1389 return @param unless (defined($param[0]) && $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         161 my $i;
30 112         416 for ($i=0;$i<@param;$i+=2) {
31 231 50       530 if (!defined($param[$i])) {
32 0         0 cluck("Hmmm in $i ".CORE::join(";", @param)." == ".CORE::join(";",@$order)."\n");
33             }
34             else {
35 231         732 $param[$i]=~s/^\-//;
36 231         915 $param[$i]=~tr/a-z/A-Z/;
37             }
38             }
39            
40             # Now we'll convert the @params variable into an associative array.
41 112         477 my(%param) = @param;
42              
43 112         158 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         163 foreach $key (@{$order}) {
  112         251  
51 339         525 $key=~tr/a-z/A-Z/;
52 339         557 my($value) = $param{$key};
53 339         544 delete $param{$key};
54 339         659 push(@return_array,$value);
55             }
56            
57             # catch user misspellings resulting in unrecognized names
58 112         278 my(@restkeys) = keys %param;
59 112 50       349 if (scalar(@restkeys) > 0) {
60 0         0 carp("@restkeys not processed in rearrange(), did you use a
61             non-recognized parameter name ? ");
62             }
63 112         594 return @return_array;
64             }
65              
66              
67             1;
68