EnsEMBL/Utils/Argument.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 58 CC 5 SCAR 22.3
CC
5
Cov
0%
rearrange_pp
20.0
BEGIN
6.0
BEGIN
2.0
CRAP 9.3
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::Utils::Argument - Utility functions for argument handling
34  
35 =head1 SYNOPSIS
36  
37 use Bio::EnsEMBL::Utils::Argument qw(rearrange)
38  
39 package Feature;
40  
41 sub new {
42 my $class = shift;
43 my ( $start, $end, $strand ) =
44 rearrange( [ 'START', 'END', 'STRAND' ], @_ );
45  
46 return
47 bless( { 'start' => $start, 'end' => $end, 'strand' => $strand },
48 $class );
49 }
50  
51 =head1 DESCRIPTION
52  
53 This is derived from the Bio::Root module in BioPerl. The _rearrange
54 object method taken from BioPerl has been renamed rearrange and is now
55 a static class method. This method was originally written by Lincoln
56 Stein, and has since been refactored several times by various people (as
57 described below).
58  
59 It is recommended that this package be used instead of inheriting
60 unnecessarily from the Bio::EnsEMBL::Root or Bio::Root object.
61  
62 =head1 METHODS
63  
64 =cut
65  
66 package Bio::EnsEMBL::Utils::Argument;
67 $Bio::EnsEMBL::Utils::Argument::VERSION = '114.0.0_50'; # TRIAL
68 $Bio::EnsEMBL::Utils::Argument::VERSION = '114.0.050';
69 use strict;
70 use warnings;
71  
72 #
73 # Interface with some of the module function XS reimplementation
74 #
75 # If Bio::EnsEMBL::XS is installed, assign the function glob to
76 # the XS counterpart, otherwise assign to the original function
77 #
78 BEGIN {
79  
80 if (eval { require Bio::EnsEMBL::XS; 1 }) {
81 *rearrange = \&Bio::EnsEMBL::XS::Utils::Argument::rearrange;
82 } else {
83 *rearrange = \&rearrange_pp;
84 }
85
86 }
87  
88 use Exporter;
89  
90 use vars qw(@ISA @EXPORT);
91  
92 @ISA = qw(Exporter);
93 @EXPORT = qw(rearrange);
94  
95  
96  
97 =head2 rearrange_pp
98  
99 Usage : rearrange( array_ref, list_of_arguments)
100 Purpose : Rearranges named parameters to requested order.
101 Example : use Bio::EnsEMBL::Utils::Argument qw(rearrange);
102 : rearrange([qw(SEQUENCE ID DESC)],@param);
103 : Where @param = (-sequence => $s,
104 : -id => $i,
105 : -desc => $d);
106 Returns : @params - an array of parameters in the requested order.
107 : The above example would return ($s, $i, $d)
108 Argument : $order : a reference to an array which describes the desired
109 : order of the named parameters.
110 : @param : an array of parameters, either as a list (in
111 : which case the function simply returns the list),
112 : or as an associative array with hyphenated tags
113 : (in which case the function sorts the values
114 : according to @{$order} and returns that new array.)
115 : The tags can be upper, lower, or mixed case
116 : but they must start with a hyphen (at least the
117 : first one should be hyphenated.)
118 Source : This function was taken from CGI.pm, written by Dr. Lincoln
119 : Stein, and adapted for use in Bio::Seq by Richard Resnick and
120 : then adapted for use in Bio::Root::Object.pm by Steve A. Chervitz.
121 : This has since been adapted as an exported static method in this
122 class Bio::EnsEMBL::Utils::Argument
123 Comments : (SAC)
124 : This method may not be appropriate for method calls that are
125 : within in an inner loop if efficiency is a concern.
126 :
127 : Parameters can be specified using any of these formats:
128 : @param = (-name=>'me', -color=>'blue');
129 : @param = (-NAME=>'me', -COLOR=>'blue');
130 : @param = (-Name=>'me', -Color=>'blue');
131 : A leading hyphenated argument is used by this function to
132 : indicate that named parameters are being used.
133 : Therefore, a ('me', 'blue') list will be returned as-is.
134 :
135 : Note that Perl will confuse unquoted, hyphenated tags as
136 : function calls if there is a function of the same name
137 : in the current namespace:
138 : -name => 'foo' is interpreted as -&name => 'foo'
139 :
140 : For ultimate safety, put single quotes around the tag:
141 : ('-name'=>'me', '-color' =>'blue');
142 : This can be a bit cumbersome and I find not as readable
143 : as using all uppercase, which is also fairly safe:
144 : (-NAME=>'me', -COLOR =>'blue');
145 :
146 : Personal note (SAC): I have found all uppercase tags to
147 : be more managable: it involves less single-quoting,
148 : the code is more readable, and there are no method naming
149 : conlicts.
150 : Regardless of the style, it greatly helps to line
151 : the parameters up vertically for long/complex lists.
152  
153 =cut
154  
155  
156 sub rearrange_pp {
157 my $order = shift;
158  
159 if ( $order eq "Bio::EnsEMBL::Utils::Argument" ) {
160 # skip object if one provided
161 $order = shift;
162 }
163  
164 # If we've got parameters, we need to check to see whether
165 # they are named or simply listed. If they are listed, we
166 # can just return them.
167 unless ( @_ && $_[0] && substr( $_[0], 0, 1 ) eq '-' ) {
168 return @_;
169 }
170
171 # Push undef onto the end if % 2 != 0 to stop warnings
172 push @_,undef unless $#_ %2;
173 my %param;
174 while( @_ ) {
175 #deletes all dashes & uppercases at the same time
176 (my $key = shift) =~ tr/a-z\055/A-Z/d;
177 $param{$key} = shift;
178 }
179
180 # What we intend to do is loop through the @{$order} variable,
181 # and for each value, we use that as a key into our associative
182 # array, pushing the value at that key onto our return array.
183 return map { $param{uc($_)} } @$order;
184 }
185  
186 1;
187  
188