NAME

Hash::AutoHash::Args - Argument list processing (version 0)

SYNOPSIS

use Hash::AutoHash::Args::V0;
my $args=new Hash::AutoHash::Args::V0(name=>'Joe',
                                    HOBBIES=>'hiking',hobbies=>'cooking');

# access argument values as HASH elements
my $name=$args->{name};
my $hobbies=$args->{hobbies};

# access argument values via methods
my $name=$args->name;
my $hobbies=$args->hobbies;

# set local variables from argument values -- three equivalent ways
use Hash::AutoHash::Args qw(autoargs_get);
my($name,$hobbies)=@$args{qw(name hobbies)};
my($name,$hobbies)=autoargs_get($args,qw(name hobbies));
my($name,$hobbies)=$args->get_args(qw(name hobbies)));

# copy args into local hash
my %args=$args->getall_args

# alias $args to regular hash for more concise hash notation
use Hash::AutoHash::Args qw(autoargs_alias);
autoargs_alias($args,%args);
my($name,$hobbies)=@args{qw(name hobbies)}; # get argument values
$args{name}='Joseph';                       # set argument value

DESCRIPTION

This class simplifies the handling of keyword argument lists. It replaces Class::AutoClass::Args. It is a subclass of Hash::AutoHash::Args providing almost complete compatibility with Class::AutoClass::Arg. We recommend that you use Hash::AutoHash::Args instead of this class unless you need compatibility with Class::AutoClass::Args.

This class is identical to Hash::AutoHash::Args except as follows. Please refer to Hash::AutoHash::Args for the main documentation.

Unlike Hash::AutoHash::Args, this class defines several methods and functions in its own namespace.

get_args, getall_args, set_args, fix_args, _fix_args, fix_keyword,
fix_keywords, is_keyword, is_positional

A consequence of these being defined in the class's namespace is that they "mask" keywords of the same name and prevent those keywords from being accessed using method notation. In Hash::AutoHash::Args, these are provided as functions that can be imported in the caller's namespace which avoids the masking problem.

get_args, getall_args, and set_args are methods that can be invoked on Hash::AutoHash::Args::V0 objects. Descriptions of these methods are below. The others are functions and operate the same way here as in Hash::AutoHash::Args except that they do not need to be imported before use.

Title   : get_args
Usage   : ($name,$hobbies)=$args->get_args(qw(-name hobbies))
Function: Get values for multiple keywords
Args    : array or ARRAY of keywords
Returns : array or ARRAY of argument values
Note    : provided in Hash::AutoHash::Args as importable function

Title   : getall_args
Usage   : %args=$args->getall_args;
Function: Get all keyword, value pairs
Args    : none
Returns : hash or HASH of key=>value pairs.
Note    : provided in Hash::AutoHash::Args as importable function

Title   : set_args
Usage   : $args->set_args
            (name=>'Joe the Plumber',-first_name=>'Joe',-last_name=>'Plumber')
Function: Set multiple arguments in existing object
Args    : parameter list in same format as for 'new'
Returns : nothing
Note    : provided in Hash::AutoHash::Args as importable function

DIFFERENCES FROM Class::AutoClass::Args

This class differs from its precursor, Class::AutoClass::Args, only in a bug fix involving get_args in scalar context.

In scalar context, get_args is supposed to return an ARRAY of argument values. Instead, in Class::AutoClass::Args, it returned the value of the first argument.

my $values=$args->get_args(qw(name hobbies)); # old bug: gets value of 'name'

The bug has been fixed and it now returns an ARRAY of the requested argument values.

my $values=get_args($args,qw(name hobbies));  # now: gets ARRAY of both values

KNOWN BUGS AND CAVEATS

CPAN reports that "Make test fails under Perl 5.6.2, FreeBSD 5.2.1." for Class::AutoClass::Args. We are not aware of any bugs in the running code.

Bugs, Caveats, and ToDos

See caveats about accessing arguments via method notation.

AUTHOR - Nat Goodman, Chris Cavnor

Email natg@shore.net

COPYRIGHT

Copyright (c) 2004, 2009 Institute for Systems Biology (ISB). All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.