Cataly...Context(3pm)

πŸ“¦
version 0.001001 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Cataly...Context(3pm) πŸ’–

okay so bestie, welcome to Catalyst::Component::InstancePerContext β€” the Perl module that gives you a brand new instance of a component on each and every request. yes, every single one. it's giving ✨fresh vibes only✨.


🌸 NAME 🌸

Catalyst::Component::InstancePerContext β€” returns a new instance a component on each request πŸ¦‹


✨ SYNOPSYS ✨

package MyComponent;
use Moose;
with 'Catalyst::Component::InstancePerContext';

sub build_per_context_instance{
    my ($self, $c) = @_;
    # ... do your thing here
    return SomeModule->new(%args);
}

πŸŽ€ REQUIRED METHODS πŸŽ€

so like, your consuming class has to implement this next one. no skipping, no shortcuts, it's mandatory bestie πŸ’…

🧚 build_per_context_instance

whatever this call hands back? that's literally what you get when you call $c->component('YourComponent'). that's the whole deal. that's the assignment 🫢


πŸ‘‘ PROVIDED METHODS πŸ‘‘

this role is gonna slide one extra method into your consuming class. consider it a gift 🎁

🌈 ACCEPT_CONTEXT

here's the tea β˜• β€” if the context is not blessed, it just simply passes through the value of "build_per_context_instance". no drama, no fuss, straight through.

but if the context is blessed? then it goes looking in the "stash" for an instance of the requested component and returns that. and if that value isn't found? then whatever "build_per_context_instance" returned gets stored, and then returned. so it's cached in the stash for the rest of the request, iykyk 😌

the idea behind this whole behaviour is that a component can be built on a per-request basis β€” which is, like, literally what the name of this module is saying. it said it in the name. the name is the point. periodt πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

  • Moose
  • Moose::Role
  • Catalyst::Component

πŸ’œ AUTHOR πŸ’œ

Guillermo Roditi (groditi) <groditi@cpan.org> β€” icon, legend, the moment πŸ‘‘


πŸ“œ LICENSE πŸ“œ

you may distribute this code under the same terms as Perl itself. slay, go forth, distribute responsibly πŸŽ€


perl v5.34.0 🌸 2022-06-09 β€” that's the version and the date bestie, and that's a wrap on Cataly...Context(3pm). mwah πŸ’‹πŸ¦‹βœ¨

πŸ“¦ where this page comes from