Object::WithParams - An Object With Params
Version 0.3
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();
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.)
Creates a new, empty Object::WithParams.
my $thingy = Object::WithParams->new;
Deletes all the extent parameters. Does not return anything.
$thingy->clear();
Returns a new Object::WithParams with the same set of parameters as the old one.
my $doodad = $thingy->clone();
Delete the named parameter.
$thingy->delete('veggie');
The param method can be called in three ways.
param
Returns a list of the parameters contained in the object.
my @params = $thingy->param();
The value of the parameter with the name of the argument will be returned.
my $color = $thingy->param('color');
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.
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.
bug-object-withparams at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Object::WithParams
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Object-WithParams
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Object-WithParams
CPAN Ratings
http://cpanratings.perl.org/d/Object-WithParams
Search CPAN
http://search.cpan.org/dist/Object-WithParams/
Jaldhar H. Vyas, <jaldhar at braincells.com>
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.
To install Object::WithParams, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Object::WithParams
CPAN shell
perl -MCPAN -e shell install Object::WithParams
For more information on module installation, please visit the detailed CPAN module installation guide.