HTML::...dMaker(3pm)

πŸ’– HTML::...dMaker(3pm) πŸ’–

User Contributed Perl Documentation ✨ so this is the page for HTML::Mason::MethodMaker, bestie πŸ’…


πŸŽ€ NAME πŸŽ€

HTML::Mason::MethodMaker β€” it's the lil module that makes simple get & get/set methods for other classes 🫢


🌸 SYNOPSIS 🌸

 use HTML::Mason::MethodMaker
     ( read_only => 'foo',
       read_write => [
                      [ bar => { type => SCALAR } ],
                      [ baz => { isa => 'HTML::Mason::Baz' } ],
                      'quux', # no validation
                     ],
       read_write_contained => { other_object =>
                                 [
                                  [ 'thing1' => { isa => 'Thing1' } ],
                                  'thing2', # no validation
                                 ]
                               },
     );

okay look at that, it's giving effortless ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

This automates the creation of simple accessor methods. that's it. that's the whole vibe πŸŽ€ like, you do NOT need to hand-write thirty little sub foo { ... } blocks, no cap πŸ’…


🌈 USAGE 🌈

This module creates methods when it is use'd by another module. There are three types of methods: 'read_only', 'read_write', 'read_write_contained'. three flavors, pick ur fighter 🧚


⭐ read_only ⭐

Attributes specified as 'read_only' get an accessor that only returns the value of the attribute. Presumably, these attributes are set via more complicated methods in the class or as a side effect of one of its methods.

so like... it's read-only fr fr, you can look but you cannot touch πŸ™ˆ the class itself is the one setting that value behind the scenes, not you.

πŸ’œ read_write πŸ’œ

Attributes specified as 'read_write' will take a single optional parameter. If given, this parameter will become the new value of the attribute. This value is then returned from the method. If no parameter is given, then the current value is returned.

it's giving dual-purpose icon behavior πŸ‘‘ pass nothing β†’ you get the value. pass something β†’ that something becomes the value, and then it gets returned to you. one method, two jobs, main character energy ✨

πŸ’– validation, aka the Params::Validate moment πŸ’–

If you want the accessor to use Params::Validate to validate any values passed to the accessor (and you _do_), then the the accessor specification should be an array reference containing two elements. The first element is the accessor name and the second is the validation spec.

bestie, please validate. it says you _do_ want this. it's italicized-and-underscored in the original, that's how serious it is 😭 so: array ref, element one = accessor name, element two = the validation spec. two things. that's the whole deal πŸŽ€

🫢 read_write_contained 🫢

The 'read_write_contained' parameter is used to create accessor for delayed contained objects. A delayed contained object is one that is not created in the containing object's accessor, but rather at some point after the containing object is constructed. For example, the Interpreter object creates Request objects after the Interpreter itself has been created.

okay so delayed contained objects β€” not built at the moment the container's accessor runs, but lowkey later, after the containing object already exists. the glow-up happens off-screen πŸ’… example straight from the source: the Interpreter object creates Request objects after the Interpreter itself has been created. iconic scheduling ngl ✨

The value of the 'read_write_contained' parameter should be a hash reference. The keys are the internal name of the contained object, such as "request" or "compiler". The values for the keys are the same as the parameters given for 'read_write' accessors.

so: hash ref. keys = the internal name of the contained object (think "request", "compiler"). values = literally the exact same stuff you'd hand to a 'read_write' accessor. reuse the formula, it ate πŸ”₯

and that's the whole page, you understood it, periodt πŸ’–βœ¨πŸŽ€

this was HTML::...dMaker(3pm) from the User Contributed Perl Documentation crew, running on perl v5.38.2, dated 2024-03-05 🌸 mwah, go write some accessors bestie πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from