MooseX::Param(3pm)

πŸ“¦
version 0.02 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 a params attribute that comes with a read-only accessor and a HashRef type constraint. it also adds a builder method to properly initialize it β€” that's the init_params method, peep below for the tea πŸ’œ

πŸ’… METHODS πŸ’…

  • params β€” hands back the HASH ref where all your parameters are actually stored. the raw goods, bestie.
  • param β€” the star of the show, your standard CGI-style param method 🌟 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's builder option, 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 the Mixin::ExtraFields framework. 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 2007 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

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