MooseX::Param(3pm)
π MooseX::Param π
okay bestie, so this is MooseX::Param β a Perl module, manual page MooseX::Param(3pm), and it's literally the "simple role to provide a standard param method" you've been wishing for. it's giving helper-role energy and we're obsessed π
β¨ NAME β¨
MooseX::Param β a simple role that hands you a standard param method. yes that's the whole pitch and honestly? iconic.
πΈ SYNOPSIS πΈ
here's the vibe, fr fr:
package My::Template::System;
use Moose;
with 'MooseX::Param';
# ...
my $template = My::Template::System->new(
params => {
foo => 10,
bar => 20,
baz => 30,
}
);
# fetching params
$template->param('foo'); # 10
# getting list of params
$template->param(); # foo, bar, baz
# setting params
$template->param(foo => 30, bar => 100);
see how chill that is? you with 'MooseX::Param', you hand it a params hashref at construction, and then you're just out here grabbing values, listing names, and setting new ones like it's nothing. main character behaviour, no cap β¨
π¦ DESCRIPTION π¦
okay so this is a very simple Moose role, and what it does is give you a CGI-like param method. that's it. that's the whole thing. and yet?? it's everything.
the author (we love him) says he found himself writing this exact same code over and over and over and over again, and every single time it was the same. so he was like... why am I doing this to myself bestie. why not put it in a role. and thus, a legend was born π«Ά
π ATTRIBUTES π
paramsβ this role gives you aparamsattribute that comes with a read-only accessor and aHashReftype constraint. it also adds a builder method to properly initialize it β that's theinit_paramsmethod, peep below for the tea π
π METHODS π
paramsβ hands back theHASHref where all your parameters are actually stored. the raw goods, bestie.paramβ the star of the show, your standard CGI-styleparammethod π here's the breakdown:- pass it no arguments β it returns a list of param names.
- pass it a single name argument β it returns the param associated with that name.
- pass it a key value pair (or a whole set of key value pairs) β it assigns them all into the params.
init_paramsβ this is the params attribute'sbuilderoption, so it gets called when the params are initialized. cute, right?
NOTE: you can override this by defining your own version in your class, because local class methods beat role methods in composition. you're the boss of your own class, periodt π
metaβ returns the role metaclass. classic, slay.
π SIMILAR MODULES π
so the param method is out here living in several other modules too β CGI, CGI::Application and HTML::Template, just to name a few. it's such a common Perl idiom that the author felt it really deserved its own role. honestly? it was partly because he was sick of re-writing and copy-pasting it all the time π relatable.
there are also a few modules that try to solve the same problem this one does. those are:
Class::Paramβ this module is much more ambitious than this one and provides way deeper functionality. for most of the author's purposes it would have been overkill, but if you need really sophisticated param handling and the ability to provide several different APIs (tied, etc.), this module is probably the way to go. if it's extra you want, it's extra you get πMixin::ExtraFields::Paramβ very similar to this module, but for a different framework. it works with theMixin::ExtraFieldsframework. same energy, different house π
π BUGS π
all complex software has bugs lurking in it and this module is no exception β no software is immune bestie, not even the cute ones π
if you find a bug, please either email the author, or add the bug to cpan-RT. your service will be remembered π«Ά
π AUTHOR π
Stevan Little <stevan@iinteractive.com>
πΈ COPYRIGHT AND LICENSE πΈ
Copyright 2007 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π this was MooseX::Param(3pm), generated for perl v5.36.0 on 2022-10-16. go forth and param responsibly β¨ππ¦
π¦ where this page comes from
- ubuntu noble: libmoosex-param-perl 0.02-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-param-perl 0.02-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-param-perl 0.02-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms