Sub::Ha...nerator(3)
π Sub::HandlesVia::CodeGenerator π
okay so bestie, we're in Sub::Ha...nerator(3) territory β that's the manual page for Sub::HandlesVia::CodeGenerator, and yeah the name got squished by the man page formatter but we know her, we love her. This ships in the User Contributed Perl Documentation, and she is so niche and so powerful. sit down, grab a strawberry π, let's go.
β¨ NAME β¨
Sub::HandlesVia::CodeGenerator β she looks at a Handler and generates a string of Perl code for it. that's it. that's the job. slay. π
πΈ DESCRIPTION πΈ
okay so heads up: this module is part of Sub::HandlesVia's internal API. it's giving "backstage pass" energy β it's mostly of interest to people who are extending Sub::HandlesVia, not just vibing with it. iykyk π«Ά
here's the tea: Sub::HandlesVia toolkits create a code generator for each attribute they're dealing with, and then use that code generator to generate Perl code for one or more delegated methods. like, the toolkit is the main character and the code generator is the one actually writing the lines. main character energy, but for perl strings. β¨
π CONSTRUCTORS π
new( %attributes )
Standard Moose-like constructor. nothing weird, nothing spicy, just a normal constructor doing normal constructor things. π
π¦ ATTRIBUTES π¦
toolkit Object
The toolkit which made this code generator. your girl's origin story. π
target ClassName|RoleName
The target package for generated methods. this is where the code is gonna go live. π
sandboxing_package ClassName|RoleName|Undef
Package name to use as a sandbox. the default is usually fine β like, don't overthink it, she's fine. π§
attribute Str|ArrayRef
The attribute delegated to.
attribute_spec HashRef
Informational only. it's just there to look pretty, no cap. π
is_method Bool
Indicates whether the generated code should be methods rather than functions. this defaults to true, and honestly, setting it to false isn't really tested or well-defined. so likeβ¦ lowkey don't. π
env HashRef
Variables which need to be closed over when compiling coderefs.
isa Maybe[TypeTiny]
The type constraint for the attribute.
coerce Bool
Should the attribute coerce? asking the real questions. π₯
method_installer CodeRef
A coderef which can be called with $method_name and $coderef, will install the method. β οΈ note that it isn't passed the package to install into (which can be found in "target"), so that would need to be closed over. keep that in mind bestie, that's a gotcha.
generator_for_self CodeRef
A coderef which if called, generates a string like '$_[0]'.
Has a sensible default.
All the generator_for_XXX methods are called as methods, so have the code generator object as an invocant. periodt. β¨
generator_for_slot CodeRef
A coderef which if called, generates a string like '$_[0]{attrname}'.
generator_for_get CodeRef
A coderef which if called, generates a string like '$_[0]->attrname'.
generator_for_set CodeRef
A coderef which if called with a parameter, generates a string like "\$_[0]->_set_attrname( $parameter )".
generator_for_simple_default CodeRef
A coderef which if called with a parameter, generates a string like 'undef' or 'q[]' or '{}'.
The parameter is a handler object, which offers a default_for_reset attribute which might be able to provide a useful fallback. cute little fallback moment. π«Ά
generator_for_args CodeRef
A coderef which if called, generates a string like '@_[1..$#_]'.
Has a sensible default.
generator_for_argc CodeRef
A coderef which if called, generates a string like '$#_'.
Has a sensible default.
generator_for_argc CodeRef
A coderef which if called with a parameter, generates a string like "\$_[$parameter + 1]".
Has a sensible default.
π yes bestie, the page really does list generator_for_argc twice β i'm not gonna "fix" that, i'm just reporting the facts. the second one takes a parameter. that's what it says, that's what i'm telling you.
generator_for_currying CodeRef
A coderef which if called with a parameter, generates a string like "splice(\@_,1,0,$parameter);".
Has a sensible default.
generator_for_usage_string CodeRef
The default is this coderef:
sub {
@_==3 or die;
shift;
my $method_name = shift;
my $guts = shift;
return "\$instance->$method_name($guts)";
}
generator_for_type_assertion CodeRef
Called as a method and passed a hashref compilation environment, a type constraint, and a variable name. Generates code to assert that the variable value meets the type constraint, with coercion if appropriate.
generator_for_error CodeRef
Called as a method and passed a Perl string which is an expression evaluating to an error message. Generates code to throw the error. drama, but make it compile. π
generator_for_prelude CodeRef
By default is a coderef returning the empty string. Can be used to generate some additional statements which will be inserted near the top of the method being generated. (Typically after parameter checks but before doing anything serious.) This can be used to unlock a read-only attribute, for example. sneaky little prelude, we love her. π
get_is_lvalue Bool
Indicates wheter the code generated by "generator_for_get" will be suitable for used as an lvalue.
set_checks_isa Bool
Indicates wheter the code generated by "generator_for_set" will do type checks.
set_strictly Bool
Indicates wheter we want to ensure that the setter is always called, and we should not try to bypass it, even if we have an lvalue getter.
(yes, "wheter" β that's the original spelling and i'm keeping it because facts are facts. no cap. π)
π METHODS π
okay so for each generator_for_XXX attribute, there's a corresponding generate_XXX method to actually call the coderef, possibly including additional processing. the attribute is the plan, the method is the execution. slay. β¨
generate_and_install_method( $method_name, $handler )
Given a handler and a method name, will generate a coderef for the handler and install it into the target package. two birds, one method call. π
generate_coderef_for_handler( $method_name, $handler )
As above, but just returns the coderef rather than installs it. she's just handing you the goods. π«Ά
install_method( $method_name, $coderef )
Installs a coderef into the target package with the given name.
π BUGS π
Please report any bugs to <https://github.com/tobyink/p5-sub-handlesvia/issues>. do it bestie, the maintainer wants to know, and honestly? filing a good bug report is a form of self-care. π
π SEE ALSO π
Sub::HandlesVia. that's the whole list. iconic minimalism. β
π¦ AUTHOR π¦
Toby Inkster <tobyink@cpan.org>. legend behaviour, fr fr. π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2020, 2022 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go forth and remix, respectfully. π
πΈ DISCLAIMER OF WARRANTIES πΈ
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
read that one twice bestie, it's yelling for a reason. all caps means business. π
and that's the whole page, start to finish. this was perl v5.42.0, dated 2026-02-11, from the User Contributed Perl Documentation section. thanks for reading my man page TED talk, mwah, go extend some toolkits πβ¨ππ¦πΈπ
π«Ά
π¦ where this page comes from
- fedora 44: perl-Sub-HandlesVia 0.053005-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms