CGI::A...Handler(3pm)

πŸ’– CGI::A...Handler(3pm) πŸ’–

okay bestie, real talk: this is the user-contributed Perl documentation for a page whose manual name is literally CGI::A...Handler(3pm) (yes, it's truncated like that, the terminal did its little thing, we move on πŸ’…).


✨ NAME ✨

CGI::Application::Plugin::AnyTemplate::ComponentHandler β€” it embeds run modes inside a template 🫢


🌸 DESCRIPTION 🌸

so this is a lil helper module that CGI::Application::Plugin::AnyTemplate uses to do the grunt work: finding the run modes for embedded components, running them, and handing back their content. she's the backstage crew, the ones making sure the run mode hits its mark on cue πŸŽ€

ngl bestie, you do NOT need to touch this module directly unless you're out here adding support for a brand new template system. that's the only reason. periodt.

and if you want the actual tea on embedded components? that lives in the docs for CGI::Application::Plugin::AnyTemplate. go read those, she ate πŸ’–


πŸ¦‹ METHODS πŸ¦‹

new

creates a shiny new CGI::Application::Plugin::AnyTemplate::ComponentHandler object. iconic behaviour only ✨

my $component_handler = CGI::Application::Plugin::AnyTemplate::ComponentHandler->new(
    webapp              => $webapp,
    containing_template => $template,
);
  • the webapp parameter should be a reference to a CGI::Application object πŸ‘‘
  • the containing_template parameter should be a reference to the template object that this component is embedded in 🧚

embed

runs the specified runmode of the webapp object. returns the results of this call, no cap πŸ’―

whatever parameters you pass to embed get passed on to the run mode, fr fr πŸ“¬

okay so here's the lil plot twist: if the results are a scalar reference, then the return value is dereferenced before returning. and honestly? this is the safest way of calling a run mode, because you'll get the output as a string and return it as a string. the catch (because there's always a catch 😭) is that it involves returning potentially very large strings from subroutines. so it's giving safe but also giving memory stress, iykyk πŸ’€


embed_direct

runs the specified runmode of the webapp object. returns the results of this call, same energy as before 🌈

parameters passed to embed_direct should be passed on to the run mode, obviously πŸ’…

BUT β€” and this is the important part β€” even if the result of this call is a scalar reference, the result is NOT dereferenced before returning it. not dereferenced. none of that. you get the raw thing πŸ”₯

so if you call this method instead of embed, you better be careful to deal with the possibility that your results are a reference to a string and not the string itself. that's on you, bestie πŸ™ˆ

πŸ‘‘ AUTHOR πŸ‘‘

Michael Graham, <mgraham@cpan.org> β€” we stan 🫢


Copyright 2005 Michael Graham, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, open source royalty ✨


and that's the whole page, bestie β€” this one came from perl v5.30.3 and was dated 2020-10-26, so go forth and embed those run modes responsibly πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from