The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Hash::Param - CGI/Catalyst::Request-like parameter-hash accessor/mutator

VERSION

Version 0.04

SYNPOSIS

    my $params = Hash::Param->new(parameters => {
        qw/a 1 b 2 c 3/,
        d => [qw/4 5 6 7/],
    })

    $result = $params->param( a )           # Returns 1
    $result = $params->param( d )           # Returns 4
    @result = $params->param( d )           # Returns 4, 5, 6, 7
    @result = $params->params               # Returns a, b, c, d
    $result = $params->params               # Returns { a => , b => 2,
                                                        c => 3, d => [ 4, 5, 6, 7 ] }
    @result = $params->params( a, b, d )    # Returns 1, 2, [ 4, 5, 6, 7 ]
    %result = $params->slice( a, b )        # Returns a => 1, b => 2

              $params->param( a => 8 )      # Sets a to 8
              $params->param( a => 8, 9 )   # Sets a to [ 8, 9 ]

DESCRIPTION

Hash::Param provides a CGI-param-like accessor/mutator for a hash

METHODS

Hash::Param->new( [ params => <params>, is => <is> ] )

Returns a new Hash::Param object with the given parameters

<params> should be a HASH reference (the object will be initialized with an empty hash if none is given)

<is> should be either ro or rw to indicate where the object is read-only or read-write, respectively

The object will be read-write by default

$params->param( <param> )

Returns the value of <param>

If the <param> value is an ARRAY reference:

In list context, returns every value of the ARRAY
In scalar context, returns just the first value of the ARRAY

$params->param( <param> => <value> )

Sets the value of <param> to <value>

Throws an error if $params is read-only

$params->param( <param> => <value>, <value>, ... )

Sets the value of <param> to an ARRAY reference consisting of [ <value>, <value>, ... ]

Throws an error if $params is read-only

$params->param

Returns a list of every param name

$params->parameter

An alias for ->param

$params->params( <param>, <param>, ... )

Returns a list containing with value of each <param>

Returns an ARRAY reference in scalar context

If $params is read-only, then each ARRAY reference value will be copied first (if any)

$params->params

Returns a hash of the parameters stored in $param

In scalar context, will return a HASH reference (which will be copied first if $params is read-only)

$params->params( <hash> )

Sets the parameters of $params via <hash> (which should be a HASH reference)

Throws an error if $params is read-only

$params->parameters

An alias for ->params

$params->data( <hash> )

Sets the parameters of $params via <hash> (which should be a HASH reference)

Throws an error if $params is read-only

$params->get( <param> )

Returns the value of <param>

Does the same as $param->param( <param> )

$params->get( <param>, <param>, ... )

Returns a list containing with value of each <param>

Does the same as $param->params( <param>, <param>, ... )

$params->get

Returns a hash of the parameters stored in $param

Does the same as $param->params

$params->slice( <param>, <param>, ... )

Returns a hash slice of <param>, <param>, ...

Returns a HASH reference in scalar context

If $params is read-only, then the slice will be cloned

SYNOPSIS

AUTHOR

Robert Krimen, <rkrimen at cpan.org>

SOURCE

You can contribute or fork this project via GitHub:

http://github.com/robertkrimen/hash-param/tree/master

    git clone git://github.com/robertkrimen/hash-param.git Hash-Param

BUGS

Please report any bugs or feature requests to bug-hash-param at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-Param. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Hash::Param

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2008 Robert Krimen, all rights reserved.

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