SPVM::Comparator - a callback type for comparation
use SPVM::Comparator; my $comparator : SPVM::Comparator = sub : int ($self : self, $obj1 : object, $obj2 : object); { my $point1 = (SPVM::Point)$obj1; my $point2 = (SPVM::Point)$obj2; if ($point1->x > $point2->x) { return 1; } elsif ($point1->x < $point2->x) { return -1; } else { return 0; } }; my $point1 = SPVM::Point->new(1, 2); my $point2 = SPVM::Point->new(5, 6); my $result = $comparator->($point1, $point2);
SPVM::Comparator is a callback type to compare objects.
sub : int ($self : self, $obj1 : object, $obj2 : object);
This method should receive two objects and return 1 if $obj1 is more than $obj2, -1 if $x is lass than $obj2, 0 if $obj1 equals $obj2 in the implementation.
To install SPVM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPVM
CPAN shell
perl -MCPAN -e shell install SPVM
For more information on module installation, please visit the detailed CPAN module installation guide.