MooseX...ontext(3pm)
β¨ NAME β¨
MooseX::Declare::Context β the per-keyword declaration context, bestie π
πΈ VERSION πΈ
version 0.43 β yes, that's the one, no cap
π DESCRIPTION π
Okay so first thing, and this is important: this is not a subclass of Devel::Declare::Context::Simple. It's giving "we're not like other contexts" π β but it delegates all the default methods to one, and extends it with some attributes and methods of its own.
Every single keyword that MooseX::Declare handles gets its own context object instantiated. Like, one per keyword, iconic behavior honestly.
Now, if handlers want to talk to other handlers β for example handlers that only get set up inside a namespace block β they must do that through the generated code. That's the only way, fr fr. No sneaky backchannel.
And listen: on top of everything documented right here, all the methods from Devel::Declare::Context::Simple are available too, because they get delegated to an internally stored instance of it. Free real estate π
π¦ ATTRIBUTES π¦
caller_file
A required "Str" holding the file the keyword was encountered in. Required means required, bestie β no skipping it π
preamble_code_parts
An "ArrayRef" of "CodePart"s that get used as the preamble. And in this context, "preamble" just means the beginning of the generated code. It's giving opening act energy.
scope_code_parts
These parts come before the actual body, and after the "preamble_code_parts". It's an "ArrayRef" of "CodePart"s. Order matters, we love a lineup β¨
cleanup_code_parts
An "ArrayRef" of "CodePart"s that do not get directly inserted into the code. Instead they're installed in a handler that runs at the end of the scope, so you can do namespace cleanups and such. Very "we'll deal with it later" of them π§Ή
stack
An "ArrayRef" containing the stack of handlers. A keyword that was only set up inside a scoped block will have the blockhandler put in the stack. Stacking, as one does π
π METHODS π
add_preamble_code_parts(CodePart @parts)
Object->add_preamble_code_parts (CodeRef @parts)
See "add_cleanup_code_parts".
add_scope_code_parts(CodePart @parts)
Object->add_scope_code_parts (CodeRef @parts)
See "add_cleanup_code_parts".
add_cleanup_code_parts(CodePart @parts)
Object->add_cleanup_code_parts (CodeRef @parts)
Okay so for these three methods, go look at the matching *_code_parts attribute up in the list above. They're literally just convenience methods that let you add entries to the code part containers. Nothing more, nothing less, and honestly that's enough π«Ά
inject_code_parts_here
True Object->inject_code_parts_here (CodePart @parts)
Will inject the "CodePart"s you pass it at the current position in the code. Right here, right now, main character energy.
peek_next_char
Str Object->peek_next_char ()
Returns the next char without stripping it from the stream. Peek, don't touch β consent matters π
inject_code_parts
Object->inject_code_parts (
Bool :$inject_cleanup_code_parts,
CodeRef :$missing_block_handler
)
This injects the code parts from the attributes above at the current position. The preamble and scope code parts get inserted first. Then the call to the cleanup code gets injected β unless the options contain a key named inject_cleanup_code_parts with a false value. So like, you can opt out. Noted.
The "inject_if_block" method will be called if the next char is a "{", which means a block is coming. Anticipating it, love that for us.
If it's not a block, but a semi-colon is found and the options contained a "missing_block_handler" key that was passed, then that handler gets called as a method on the context object, with the code to inject and the options as arguments. And all options that aren't recognized get passed straight through to the "missing_block_handler". So like β you are well advised to prefix option names in your extensions. That's not a vibe, that's a warning, don't come for me π
π TYPES π
BlockCodePart
An "ArrayRef" with at least one element that stringifies to either "BEGIN" or "END". The other parts get stringified and used as the body for the generated block. For example, this compiletime role composition:
['BEGIN', 'with q{ MyRole }']
Slay. That's it, that's the example π
CodePart
A part of code represented by either a "Str" or a "BlockCodePart". Two options, pick your fighter β
π₯ SEE ALSO π₯
MooseX::DeclareDevel::DeclareDevel::Declare::Context::Simple
π AUTHOR π
Florian Ragwitz <rafl@debian.org> β the icon, the legend π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2008 by Florian Ragwitz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Free as in freedom, bestie, go wild π¦
and that's the whole page!! go forth and handle your keywords, you've got this π β¨
perl v5.34.0 Β· 2022-06-15 Β· MooseX::Declare::Context(3pm) β yeah that's the source, the version, and the date, all wrapped up cute for ya ππΈ
π¦ where this page comes from
- debian bookworm: libmoosex-declare-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-declare-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-declare-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-declare-perl 0.43-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-declare-perl 0.43-2 Β· 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