Venus::Role::Comparable - Comparable Role
Comparable Role for Perl 5
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);
This package modifies the consuming package and provides methods for performing numerical and stringwise comparision operations or any object or raw data type.
This package provides the following methods:
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
0.08
package main; my $example = Example->new; my $result = $example->eq($example); # 1
package main; my $example = Example->new; my $result = $example->eq([1,2]); # 0
package main; my $example = Example->new; my $result = $example->eq({1..4}); # 0
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.
package main; my $example = Example->new; my $result = $example->ge(3); # 0
package main; my $example = Example->new; my $result = $example->ge($example); # 1
package main; my $example = Example->new; my $result = $example->ge([1,2,3]); # 0
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.
package main; my $example = Example->new; my $result = $example->gele(1, 3); # 1
package main; my $example = Example->new; my $result = $example->gele(2, []); # 0
package main; my $example = Example->new; my $result = $example->gele(0, '3'); # 1
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.
package main; my $example = Example->new; my $result = $example->gt({1..2}); # 0
package main; my $example = Example->new; my $result = $example->gt(1.9998); # 1
package main; my $example = Example->new; my $result = $example->gt(\1_000_000); # 0
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.
package main; my $example = Example->new; my $result = $example->gtlt('1', 3); # 1
package main; my $example = Example->new; my $result = $example->gtlt({1..2}, {1..4}); # 0
package main; my $example = Example->new; my $result = $example->gtlt('.', ['.']); # 1
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.
package main; my $example = Example->new; my $result = $example->le('9'); # 1
package main; my $example = Example->new; my $result = $example->le([1..2]); # 1
package main; my $example = Example->new; my $result = $example->le(\1); # 0
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.
package main; my $example = Example->new; my $result = $example->lt(qr/.*/); # 1
package main; my $example = Example->new; my $result = $example->lt('.*'); # 0
package main; my $example = Example->new; my $result = $example->lt('5'); # 1
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.
package main; my $example = Example->new; my $result = $example->ne([1,2]); # 1
package main; my $example = Example->new; my $result = $example->ne([2]); # 1
package main; my $example = Example->new; my $result = $example->ne(qr/2/); # 1
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.
package main; my $example = Example->new; my $result = $example->tv($example); # 1
package main; use Venus::Number; my $example = Example->new; my $result = $example->tv(Venus::Number->new(2)); # 0
package main; use Venus::String; my $example = Example->new; my $result = $example->tv(Venus::String->new('2')); # 0
package main; use Venus::String; my $example = Example->new; my $result = $example->tv(Example->new); # 1
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.