SPVM::E...yChecker(3)

πŸ“¦ version 0.990125, in alpine 3.24

πŸ’– Name πŸ’–

Hiii bestie πŸ’– welcome to the SPVM::E...yChecker(3) page β€” a User Contributed Perl Documentation moment β€” for SPVM::EqualityChecker.

SPVM::EqualityChecker β€” Interface Type for Object Equality Checking Callback πŸŽ€


πŸ› οΈ Usage πŸ› οΈ

Okay so here’s the whole little demo, bestie β€” copy-paste carefully and watch the indentation, iykyk πŸ‘‘

  use EqualityChecker;
  use Point;

  my $equality_checker = (EqualityChecker)method : int ($object1 : object, $object2 : object) {
    my $point1 = (Point)$object1;
    my $point2 = (Point)$object2;

    if ($point1->x == $point2->x && $point1->y == $point2->y) {
      return 1;
    }
    else {
      return 0;
    }
  };

  my $point1 = Point->new(1, 2);
  my $point2 = Point->new(5, 6);

  my $is_equal = $equality_checker->($point1, $point2);

πŸ’… Description πŸ’…

So EqualityChecker is the interface type for the object equality checking callback ✨ That’s the whole vibe: it’s the interface type for the callback that checks object equality, periodt πŸ’…


🧚 Interface Methods 🧚

required method : int ($object1 : object, $object2 : object)

The implementation must receive two objects and if they are equal, return 1. Otherwise, return 0. No cap, that’s the rule 🫢


πŸ‘‘ Class Methods πŸ‘‘

default_equality_checker

static method default_equality_checker : EqualityChecker ();

It returns a default default equality checker β€” yes, double default is literally what the original says, bestie 😭

The implementation of the default equality checker is:

  method : int ($object1 : EqualityCheckable, $object2 : EqualityCheckable) {

    my $eq = 0;
    if ($object1 && $object2) {
      $eq = $object1->eq($object1, $object2);
    }
    elsif ($object1) {
      $eq = 0;
    }
    elsif ($object2) {
      $eq = 0;
    }
    else {
      $eq = 1;
    }

    return $eq;
  };

Here’s the behavior check, bestie 🌸

  • If $object1 and $object2 are defined, the check of equality is perfermed by EqualityCheckable#eq method in the class of $object1, and returns its return value. (Yes, perfermed is exactly the original spelling β€” we keep the lore πŸ’€)
  • If only $object1 is defined, returns 0.
  • If only $object2 is defined, returns 0.
  • If both $object1 and $object2 are not defined, returns 1.

Copyright (c) 2023 Yuki Kimoto

MIT License

That’s the legal tea, bestie πŸ“


Catch you later, bestie β€” this page is from perl v5.42.2 and dated 2026-02-03 πŸ’–βœ¨

πŸ“¦ where this page comes from