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

NAME

Object::WithParams - An Object With Params

VERSION

Version 0.3

SYNOPSIS

    use Object::WithParams;

    my $thingy = Object::WithParams->new();

    # set a param
    $thingy->param(veggie => 'tomato');
    
    # get a param
    my $veggie = $thingy->param('veggie'); # $veggie eq 'tomato'
    
    # get all params
    my @params = $thingy->param(); # @params == ('veggie')
    
    # clone a Object::WithParams
    my $doodad = $thingy->clone; # $doodad->param('veggie') == 'tomato'

    # delete a param
    $thingy->delete('veggie');
    
    # delete all params
    $thingy->clear();
    

DESCRIPTION

Use this module to create objects that do nothing except contain parameters defined by you which you can get and set as you wish. Many modules such as Data::FormValidator have methods that accept an object with a param() method and this object should be compatible with all of them.

This module really ought to be a role but there is no standardized way to do that in Perl 5. (Not everyone uses Moose.)

METHODS

new

Creates a new, empty Object::WithParams.

my $thingy = Object::WithParams->new;

clear

Deletes all the extent parameters. Does not return anything.

$thingy->clear();

clone

Returns a new Object::WithParams with the same set of parameters as the old one.

my $doodad = $thingy->clone();

delete

Delete the named parameter.

$thingy->delete('veggie');

param

The param method can be called in three ways.

with no arguments.

Returns a list of the parameters contained in the object.

my @params = $thingy->param();

with a single scalar argument.

The value of the parameter with the name of the argument will be returned.

my $color = $thingy->param('color');

with named arguments

A parameter is created for one or more sets of keys and values.

$thingy->param(filename => 'logo.jpg', height => 50, width => 100);

You could also use a hashref.

my $arg_ref = { filename => 'logo.jpg', height => 50, width => 100 }; $thingy->param($arg_ref);

The value of a parameter need not be a scalar, it could be any any sort of reference even a coderef.

$thingy->param(number => &pick_a_random_number);

Does not return anything.

BUGS

Not all possible param handling functionality is supported. Should it be?

Please report any bugs or feature requests to bug-object-withparams at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object-WithParams. 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 Object::WithParams

You can also look for information at:

AUTHOR

Jaldhar H. Vyas, <jaldhar at braincells.com>

COPYRIGHT

Copyright (C) 2010, Consolidated Braincells Inc. All Rights Reserved.

This distribution is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or

b) the Artistic License version 2.0.

The full text of the license can be found in the LICENSE file included with this distribution.