[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18, Mon Nov 30 18:08:25 2009 UTC revision 1.19, Thu Dec 3 15:34:16 2009 UTC
# Line 105  Line 105 
105    
106  =head3 GetIdList  =head3 GetIdList
107    
108      my $ids = ServerThing::GetIdList($name => $args);      my $ids = ServerThing::GetIdList($name => $args, $optional);
109    
110  Get a named list of IDs from an argument structure. If the IDs are  Get a named list of IDs from an argument structure. If the IDs are
111  missing, or are not a list, an error will occur.  missing, or are not a list, an error will occur.
# Line 120  Line 120 
120    
121  Argument structure from which the ID list is to be extracted.  Argument structure from which the ID list is to be extracted.
122    
123    =item optional (optional)
124    
125    If TRUE, then a missing value will not generate an error. Instead, an empty list
126    will be returned. The default is FALSE.
127    
128  =item RETURN  =item RETURN
129    
130  Returns a reference to a list of IDs taken from the argument structure.  Returns a reference to a list of IDs taken from the argument structure.
# Line 130  Line 135 
135    
136  sub GetIdList {  sub GetIdList {
137      # Get the parameters.      # Get the parameters.
138      my ($name, $args) = @_;      my ($name, $args, $optional) = @_;
139      # Try to get the IDs from the argument structure.      # Try to get the IDs from the argument structure.
140      my $retVal = $args->{$name};      my $retVal = $args->{$name};
141      # Throw an error if no member was found.      # Was a member found?
142      Confess("No '$name' parameter found.") if ! defined $retVal;      if (! defined $retVal) {
143      # Get the parameter type. We was a list reference. If it's a scalar, we'll          # No. If we're optional, return an empty list; otherwise throw an error.
144      # convert it to a singleton list. If it's anything else, it's an error.          if ($optional) {
145                $retVal = [];
146            } else {
147                Confess("No '$name' parameter found.");
148            }
149        } else {
150            # Here we found something. Get the parameter type. We was a list reference.
151            # If it's a scalar, we'll convert it to a singleton list. If it's anything
152            # else, it's an error.
153      my $type = ref $retVal;      my $type = ref $retVal;
154      if (! $type) {      if (! $type) {
155          $retVal = [$retVal];          $retVal = [$retVal];
156      } elsif ($type ne 'ARRAY') {      } elsif ($type ne 'ARRAY') {
157          Confess("The '$name' parameter must be a list.");          Confess("The '$name' parameter must be a list.");
158      }      }
159        }
160      # Return the result.      # Return the result.
161      return $retVal;      return $retVal;
162  }  }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3