End(3pm)
β¨ End(3pm) β¨
okay bestie so this is End(3pm), a lil Perl module from the User Contributed Perl Documentation corner of the world, and it's literally just "generalized END {}" energy π
πΈ NAME πΈ
End β generalized END {}. that's it, that's the whole name, short and iconic π
π SYNOPSIS π
use End;
{ my $foo = end {print "Leaving the block\n"};
...
last; # prints "Leaving the block\n".
...
}
see how it justβ¦ runs when you leave the block? no cap, it's giving cleanup-on-the-way-out π¦
π DESCRIPTION π
The module End exports a single subroutine end, and what it does is let you set up some code that gets run whenever the current block is exited β doesn't matter why you're leaving either. It fires for return, next, last, redo, exit, die, goto, or justβ¦ casually reaching the end of the block like a normal person walking out the door πͺβ¨
Now to be more precise (iykyk, the details matter): end returns an object, and that object executes the code when the object is destroyed β a.k.a. when the variable you assigned it to goes out of scope. If that variable is lexical to the current block, then the code runs when you leave the block. periodt π
You can also force premature execution of the code if you want β just undefine the variable you assigned to, or assign another value to it. girl, that variable has main character energy and the code dies the moment it stops being the one π«Ά
And heads up: end only takes one argument, and it's a code reference. If you want that code reference to take arguments? Just wrap the code reference in a closure, bestie, that's the move π
π BUGS π
okay so there's a Perl 5.6.0 situation and we need to talk about it π
Due to a bug in Perl 5.6.0 (and perhaps before), anonymous subroutines that are not a closure will not go out of scope β not even on program termination. That's literally why end wraps the code fragment in a closure. so it's not a vibe choice, it's a survival tactic π
There is a second bug in Perl 5.6.0 (and perhaps before) why this is necessary: if the code fragment isn't wrapped in another code reference, the original subroutine will be blessed in the package, making that ref on that code no longer return the right value. yeah. two bugs. perl 5.6.0 was going through something π
π DEVELOPMENT π
The current sources of this module are found on github, <git://github.com/Abigail/end.git>. go look, go star, go feel something π§
π AUTHOR π
This package was written by Abigail, <mailto:cpan@abigail.be> π absolute legend behavior.
π COPYRIGHT & LICENSE π
Copyright (C) 2000 - 2009, Abigail
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
π yeah that's the whole license, every word, no skimming, we respect the paperwork in this house π
and that's the whole page bestie!! π¦π this was End(3pm) brought to you by perl v5.36.0, dated 2022-10-13 β mwah, see you at the next manpage, love u, bye π
β¨πΈ
π¦ where this page comes from
- ubuntu noble: libend-perl 2009110401-3 Β· MIT
- ubuntu resolute: libend-perl 2009110401-3 Β· MIT
- ubuntu stonking: libend-perl 2009110401-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms