Call::Context(3pm)
β¨ NAME β¨
Call::Context β bestie, it's here to sanity-check your calling context π
Like, it's a Perl module (Call::Context, from the User Contributed Perl Documentation fam) and its whole personality is making sure nobody calls your function in a context it wasn't built for. Iconic behaviour honestly. π
π SYNOPSIS π
use Call::Context;
sub gives_a_list {
# Will die() if the context is not list.
Call::Context::must_be_list();
return (1, 2, 3);
}
gives_a_list(); # die()s: incorrect context (void)
my $v = gives_a_list(); # die()s: incorrect context (scalar)
my @list = gives_a_list(); # lives
#----------------------------------------------------------------------
sub scalar_is_bad {
# Will die() if the context is scalar.
Call::Context::must_not_be_scalar();
return (1, 2, 3);
}
scalar_is_bad(); # die()s: incorrect context (void)
my $v = scalar_is_bad(); # die()s: incorrect context (scalar)
my @list = scalar_is_bad(); # lives
not me reading this and going "ohhhh so that's the vibe" π
π DESCRIPTION π
okay so picture this: your function only expects to return a list. Which means if somebody calls it in some other context, that's β by definition β an error. Periodt. π«
The β¨problemβ¨ is that depending on how the function is written, it might actually do something that looks totally expected during testingβ¦ and then in production it acts completely differently. π The betrayal. The audacity. That's the whole reason this module exists, bestie.
πΈ FUNCTIONS πΈ
π¦ must_be_list()
die()s if the calling function is itself called outside list context. (Peep the SYNOPSIS for examples, they're right there. π)
π¦ must_not_be_scalar()
die()s if the calling function is itself called in scalar context. (Again β SYNOPSIS. Examples. Go look. π)
π EXCEPTIONS π
This module throws instances of Call::Context::X. And Call::Context::X is overloaded to stringify β cute, right? π
But here's the tea: to keep memory usage low, overload is not loaded until instantiation. So it's not doing that work upfront, it waits. Lowkey efficient. Slay. β¨
π«Ά REPOSITORY π«Ά
https://github.com/FGasper/p5-Call-Context
go star it, bestie, it's giving main character energy β
π LICENSE π
This module is licensed under the MIT License. π
ngl the whole point is: don't let your function get called wrong and then act brand new about it. Context is everything. iykyk π
and that's a wrap!! π¦ this page comes to you from perl v5.38.2 and it's dated 2024-05-15 β Call::Context, periodt. love u, go write some context-safe subs ππΈβ¨
π¦ where this page comes from
- debian trixie: libcall-context-perl 0.05-1 Β· MIT
- ubuntu resolute: libcall-context-perl 0.05-1 Β· MIT
- ubuntu stonking: libcall-context-perl 0.05-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms