Lexica...Objects(3pm)
π Lexical::Failure::Objects π
okay so bestie, this is a page from the User Contributed Perl Documentation, it's a 3pm manual page, and honestly? It's giving underrated bop. π
πΈ NAME πΈ
Lexical::Failure::Objects β special failure objects for Lexical::Failure. That's the whole vibe. Periodt. β¨
π VERSION π
This document describes Lexical::Failure::Objects version 0.000001. Yeah bestie, that's a lot of zeros, but we love her anyway. π«Ά
π¦ DESCRIPTION π¦
So. This module implements the "failure objects" that get returned by the optional 'failobj' mechanism of the Lexical::Failure module. It's a whole little support cast for one feature, and honestly? Main character energy. π
When ON_FAILURE 'failobj' is in effect, every single call to fail hands you back one of these objects. And these objects are special β they simulate a special out-of-band value that you can either:
- explicitly test for failure, or
- simply ignore, in which case you automatically get an exception. π
For example, given the subroutine:
package Math;
use Lexical::Failure;
sub inverse_square {
my ($n) = @_;
if ($n == 0) {
fail "Can't invert zero";
}
return 1/$n**2;
}
when 'failobj' is the selected failure signalling strategy:
use Math (fail => 'failobj')
then failure can either be tested for explicitly:
# This block skipped if $n == 0...
if (my $inv_sq = Math::inverse_square($n) {
print $inv_sq;
}
or else simply ignored β and in that case an exception will automatically be thrown:
print inverse_square($n); # ...throw exception if $n == 0
no cap, the object literally knows whether you cared or not. π§
π INTERFACE π
Here's the tea. If a failure object is used as a boolean, it evaluates false β i.e. it acts as if ON_FAILURE 'undef' had been in effect.
But if it's used as a value in any other way β as a string, as a reference, as a regex, as a filehandle, etc., etc. β or if it's just ignored and allowed to go out of scope without being evaluated at all, then a failure object throws an exception (i.e. it acts as if ON_FAILURE 'croak' had been in effect). Lowkey iconic behaviour, highkey dangerous if you're not paying attention. π
π§ Constructor (new())
The class's constructor expects two named arguments:
$failure_obj = Lexical::Failure::Objects->new(
msg => $MESSAGE_STR_OR_OBJ,
context => [$PACKAGE, $FILE, $LINE, $SUBNAME],
);
bestie, listen: you should never normally need to construct failure objects directly. It's way better to just letLexical::Failurecreate them automatically via its'failobj'mechanism. Let the module cook. π
β¨ Methods
Lexical::Failure::Objects also provides four methods you can use to query the location of the failure that they represent. None of these methods takes any arguments. Not one. Zero. Zilch. π
$failobj->subname()β returns the name of the subroutine in which the failure was signaled. That is, the equivalent of(caller 0)[3].$failobj->file()β returns the name of the file containing the subroutine call from which failure was signaled. That is, the equivalent of(caller 0)[1].$failobj->line()β returns the line number of the subroutine call from which failure was signaled. That is, the equivalent of(caller 0)[2].$failobj->context()β returns a string summarizing the info from the previous three methods, in the form:
"call to <subname> at <file> line <line>"
π©Ί DIAGNOSTICS π©Ί
They've got none of their own. None! They're just vibing.
If they do throw an exception (when misused or ignored, bestie, we talked about this), it will be the exception that fail would otherwise have thrown. So it's borrowed drama. π
βοΈ CONFIGURATION AND ENVIRONMENT βοΈ
Lexical::Failure::Objects requires no configuration files or environment variables. Nothing to set up, nothing to export, she just works. Slay. β¨
π¦ DEPENDENCIES π¦
Requires the Hash::Util::FieldHash module. That's it, that's the list. π«Ά
π« INCOMPATIBILITIES π«
None reported. Clean girl aesthetic. πΈ
π BUGS AND LIMITATIONS π
No bugs have been reported. (A flawless queen, allegedly. π)
Please report any bugs or feature requests to bug-lexical-failure@rt.cpan.org, or through the web interface at <http://rt.cpan.org>.
π AUTHOR π
Damian Conway "<DCONWAY@cpan.org>"
π LICENCE AND COPYRIGHT π
Copyright (c) 2013, Damian Conway "<DCONWAY@cpan.org>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
β οΈ DISCLAIMER OF WARRANTY β οΈ
okay bestie this part is ALL CAPS for a reason, so read it, don't skim it π
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
and that's the whole page, bestie!! π this footer was stamped out by perl v5.36.0 on 2023-08-01, and the page itself goes by Lexica...Objects(3pm) β go forth and let your failure objects be as dramatic as they wanna be. mwah. π
π
π¦ where this page comes from
- debian trixie: liblexical-failure-perl 0.001001-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblexical-failure-perl 0.001001-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblexical-failure-perl 0.001001-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblexical-failure-perl 0.001001-1 Β· 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