NAME
Venus::Role::Comparable - Comparable Role
ABSTRACT
Comparable Role for Perl 5
SYNOPSIS
package Example;
use Venus::Class;
base 'Venus::Kind';
with 'Venus::Role::Comparable';
sub numified {
return 2;
}
package main;
my $example = Example->new;
# my $result = $example->eq(2);
DESCRIPTION
This package modifies the consuming package and provides methods for performing numerical and stringwise comparision operations or any object or raw data type.
METHODS
This package provides the following methods:
eq
eq(Any $arg) (Bool)
The eq method performs an "equals" operation using the invocant and the argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
ge
ge(Any $arg) (Bool)
The ge method performs a "greater-than-or-equal-to" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
gele
gele(Any $arg1, Any $arg2) (Bool)
The gele method performs a "greater-than-or-equal-to" operation on the 1st argument, and "lesser-than-or-equal-to" operation on the 2nd argument. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
gt
gt(Any $arg) (Bool)
The gt method performs a "greater-than" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
gtlt
gtlt(Any $arg1, Any $arg2) (Bool)
The gtlt method performs a "greater-than" operation on the 1st argument, and "lesser-than" operation on the 2nd argument. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
- gtlt example 2
-
package main; my $example = Example->new; my $result = $example->gtlt({1..2}, {1..4}); # 0
- gtlt example 3
-
package main; my $example = Example->new; my $result = $example->gtlt('.', ['.']); # 1
is
is(Any $arg) (Bool)
The is method performs an "is-exactly" operation using the invocant and the argument provided. If the argument provided is blessed and exactly the same as the invocant (i.e. shares the same address space) the operation will return truthy.
Since 1.80
le
le(Any $arg) (Bool)
The le method performs a "lesser-than-or-equal-to" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
lt
lt(Any $arg) (Bool)
The lt method performs a "lesser-than" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
ne
ne(Any $arg) (Bool)
The ne method performs a "not-equal-to" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
st
st(Object $arg) (Bool)
The st method performs a "same-type" operation using the invocant and argument provided. If the argument provided is an instance of the invocant, or a subclass, the operation will return truthy.
Since 1.80
- st example 2
-
package main; use Venus::Number; my $example = Example->new; my $result = $example->st(Venus::Number->new(2)); # 0
- st example 3
-
package main; use Venus::String; my $example = Example->new; my $result = $example->st(Venus::String->new('2')); # 0
- st example 4
-
package Example2; use base 'Example'; package main; use Venus::String; my $example = Example2->new; my $result = $example->st(Example2->new); # 1
tv
tv(Any $arg) (Bool)
The tv method performs a "type-and-value-equal-to" operation using the invocant and argument provided. The operation will be performed as either a numerical or stringwise operation based upon the preference (i.e. the return value of the "comparer" method) of the invocant.
Since 0.08
- tv example 2
-
package main; use Venus::Number; my $example = Example->new; my $result = $example->tv(Venus::Number->new(2)); # 0