NAME Params::Smart - use both positional and named arguments in a subroutine SYNOPSIS use Params::Smart; sub my_sub { %args = Params(qw( +foo +bar ?bo ?baz ))->args(@_); ... } my_sub( foo=> 1, bar=>2, bo=>3 ); # call with named arguments my_sub(1, 2, 3); # same, with positional args DESCRIPTION This module allows you to have subroutines which take both named and positional arguments without having to use a changed syntax and source filters. Usage is as follows: %values = Params( @template )->( @args ); @template specifies the names of parameters in the order that they should be given in subroutine calls. @args is the list of argument to be parsed: usually you just specify the void list @_. By default, parameters are assumed to be optional. (You may insert a question mark before the name, "?name" to emphasize that it is optional for anyone reading the code.) If a plus sign is added before the name, "+name" then it will be considered a required argument. No required argument can follow an optional argument. If an asterisk is specified, the parameter will slurp all remaining arguments into a list reference. The resulting hash contains appropriate values. It may also contain additional keys which begin with an underscore. These are internal/diagnostic values. Because Perl5 treats hashes as lists, this module attempts to interpret the arguments as a hash of named parameters first. If one hash key does not match, it will assume there is a typo and return an error. If more do not match, it will assume these are positional parameters instead. The downside is that if your positional parameters coincidentally match parameter names, you will have some frustrating bugs. In such cases you can check the "_named" parameter. CAVEATS *This is an experimental module, and the interface may change.* More likely additional features will be added. SEE ALSO Params::Validate Perl6::Subs AUTHOR Robert Rothenberg Suggestions and Bug Reporting Feedback is always welcome. Please use the CPAN Request Tracker at to submit bug reports. LICENSE Copyright (c) 2005 Robert Rothenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.