Except...ertion(3pm)

πŸ“¦
version 0.0504 Β· 3 versions
, in opensuse-leap 16.0

πŸ’… NAME πŸ’…

Exception::Assertion β€” the exception that gets thrown when an assertion fails, bestie. That's it, that's the vibe.

Like, this is the 3pm perl manpage for it, and we're gonna go through the whole thing together, no skipping, promise 🫢


✨ SYNOPSIS ✨

okay so here's how you actually use it, copy-paste ready, don't @ me:

  use Exception::Assertion;

  sub assert_foo {
      my $self = eval { $_[0]->isa(__PACKAGE__) } ? shift : __PACKAGE__;
      my ($condition, $message) = @_;
      Exception::Assertion->throw(
          message => $message,
          reason  => 'foo failed',
      ) unless $condition;
  }

  assert_foo( 0, 'assert_foo failed' );

literally just use it, throw it when your condition isn't giving, and you're done πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

So this class extends the standard Exception::Base β€” it's the glow-up version β€” and it gets thrown whenever an assertion is failed. Like, the vibe check did not pass, so here's your exception πŸ“‰

It comes with an extra attribute called reason that holds the detailed message about why the assertion failed (iykyk, the receipts). And the exception has its verbosity raised too β€” more on that down below, keep reading πŸ‘‘


🧚 INHERITANCE 🧚

  • extends Exception::Base

that's the whole family tree, she's an icon, she's a daughter of Exception::Base πŸ’œ


🌸 CONSTANTS 🌸

ATTRS : HashRef

This is the declaration of class attributes, as a reference to a hash. Lowkey the blueprint for everything the class holds ✨

See Exception::Base for the details on how this works.

πŸŽ€ ATTRIBUTES πŸŽ€

This class brings new attributes to the table. For all the other descriptions, go look at Exception::Base β€” she's got the full lore.

  • reason : Str β€” contains the additional message that the assertion method fills in. It's literally the "why it failed" field, and it slays πŸ’…
  • message : Str = "Unknown assertion failed" β€” contains the message of the exception. Heads up: this class overrides the default value that comes from the Exception::Base class. So if you don't set it, you get "Unknown assertion failed", no cap πŸ™ˆ
  • verbosity : Int = 3 β€” the default verbosity for an assertion exception is raised to 3. Yep, this class overrides the default from Exception::Base too. She's just louder, that's her main character energy πŸ”₯
  • string_attributes : ArrayRef[Str] = ["message", "reason"] β€” this meta-attribute holds the format used for the string representation of the exception object. Again: this class overrides the Exception::Base default, because she has opinions πŸ¦‹

⭐ SEE ALSO ⭐

  • Exception::Base
  • Test::Assertion

go read those too, bestie, they're the supporting cast 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Piotr Roszatycki <dexter@cpan.org> β€” absolute legend, we stan πŸ’–


Copyright (C) 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>


and that's the whole page, periodt πŸŽ€ this was perl v5.42.0, dated 2011-08-24, and it's the Except...ertion(3pm) manpage β€” ily, go write some assertions that pass πŸ’œβœ¨

πŸ“¦ where this page comes from