Venus::Code
Code Class
Code Class for Perl 5
method: call method: cast method: compose method: conjoin method: curry method: default method: disjoin method: eq method: ge method: gele method: gt method: gtlt method: le method: lt method: ne method: new method: next method: rcurry method: tv
package main;
use Venus::Code;
my $code = Venus::Code->new(sub {
my (@args) = @_;
return [@args];
});
# $code->call(1..4);
This package provides methods for manipulating subroutines.
Venus::Kind::Value
The call method executes and returns the result of the code.
call(any @data) (any)
{ since => '0.01', }
=example-1 call
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { ($_[0] // 0) + 1 });
my $call = $code->call;
# 1
The cast method converts "value" objects between different "value" object types, based on the name of the type provided. This method will return undef if the invocant is not a Venus::Kind::Value.
cast(string $kind) (object | undef)
{ since => '0.08', }
=example-1 cast
package main;
use Venus::Code;
my $code = Venus::Code->new(sub{[@_]});
my $cast = $code->cast('array');
# bless({ value => [sub { ... }] }, "Venus::Array")
The compose method creates a code reference which executes the first argument (another code reference) using the result from executing the code as it's argument, and returns a code reference which executes the created code reference passing it the remaining arguments when executed.
compose(coderef $code, any @data) (coderef)
{ since => '0.01', }
=example-1 compose
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { [@_] });
my $compose = $code->compose($code, 1, 2, 3);
# sub { ... }
# $compose->(4, 5, 6); # [[1,2,3,4,5,6]]
The conjoin method creates a code reference which execute the code and the argument in a logical AND operation having the code as the lvalue and the argument as the rvalue.
conjoin(coderef $code) (coderef)
{ since => '0.01', }
=example-1 conjoin
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { $_[0] % 2 });
my $conjoin = $code->conjoin(sub { 1 });
# sub { ... }
# $conjoin->(0); # 0
# $conjoin->(1); # 1
# $conjoin->(2); # 0
# $conjoin->(3); # 1
# $conjoin->(4); # 0
The curry method returns a code reference which executes the code passing it the arguments and any additional parameters when executed.
curry(any @data) (coderef)
{ since => '0.01', }
=example-1 curry
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { [@_] });
my $curry = $code->curry(1, 2, 3);
# sub { ... }
# $curry->(4,5,6); # [1,2,3,4,5,6]
The default method returns the default value, i.e. sub{}.
default() (coderef)
{ since => '0.01', }
=example-1 default
# given: synopsis;
my $default = $code->default;
# sub {}
The disjoin method creates a code reference which execute the code and the argument in a logical OR operation having the code as the lvalue and the argument as the rvalue.
disjoin(coderef $code) (coderef)
{ since => '0.01', }
=example-1 disjoin
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { $_[0] % 2 });
my $disjoin = $code->disjoin(sub { -1 });
# sub { ... }
# disjoin->(0); # -1
# disjoin->(1); # 1
# disjoin->(2); # -1
# disjoin->(3); # 1
# disjoin->(4); # -1
The eq method performs an "equals" operation using the argument provided.
eq(any $arg) (boolean)
{ since => '0.08', }
=example-1 eq
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->eq($rvalue);
# 0
The ge method performs a "greater-than-or-equal-to" operation using the argument provided.
ge(any $arg) (boolean)
{ since => '0.08', }
=example-1 ge
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->ge($rvalue);
# 1
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.
gele(any $arg1, any $arg2) (boolean)
{ since => '0.08', }
=example-1 gele
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gele($rvalue);
# 0
The gt method performs a "greater-than" operation using the argument provided.
gt(any $arg) (boolean)
{ since => '0.08', }
=example-1 gt
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gt($rvalue);
# 1
The gtlt method performs a "greater-than" operation on the 1st argument, and "lesser-than" operation on the 2nd argument.
gtlt(any $arg1, any $arg2) (boolean)
{ since => '0.08', }
=example-1 gtlt
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->gtlt($rvalue);
# 0
The le method performs a "lesser-than-or-equal-to" operation using the argument provided.
le(any $arg) (boolean)
{ since => '0.08', }
=example-1 le
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->le($rvalue);
# 0
The lt method performs a "lesser-than" operation using the argument provided.
lt(any $arg) (boolean)
{ since => '0.08', }
=example-1 lt
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->lt($rvalue);
# 0
The ne method performs a "not-equal-to" operation using the argument provided.
ne(any $arg) (boolean)
{ since => '0.08', }
=example-1 ne
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->ne($rvalue);
# 1
The new method constructs an instance of the package.
new(any @args) (Venus::Code)
{ since => '4.15', }
The next method is an alias to the call method. The naming is especially useful (i.e. helps with readability) when used with closure-based iterators.
next(any @data) (any)
{ since => '0.01', }
=example-1 next
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { $_[0] * 2 });
my $next = $code->next(72);
# 144
The rcurry method returns a code reference which executes the code passing it the any additional parameters and any arguments when executed.
rcurry(any @data) (coderef)
{ since => '0.01', }
=example-1 rcurry
package main;
use Venus::Code;
my $code = Venus::Code->new(sub { [@_] });
my $rcurry = $code->rcurry(1,2,3);
# sub { ... }
# $rcurry->(4,5,6); # [4,5,6,1,2,3]
This package overloads the &{} operator.
The tv method performs a "type-and-value-equal-to" operation using argument provided.
tv(any $arg) (boolean)
{ since => '0.08', }
=example-1 tv
package main;
use Venus::Array;
use Venus::Code;
my $lvalue = Venus::Code->new;
my $rvalue = Venus::Array->new;
my $result = $lvalue->tv($rvalue);
# 0
t/Venus.t: present: authors t/Venus.t: present: license
153 POD Errors
The following errors were encountered while parsing the POD:
- Around line 14:
Unknown directive: =name
- Around line 22:
Unknown directive: =tagline
- Around line 30:
Unknown directive: =abstract
- Around line 38:
Unknown directive: =includes
- Around line 64:
Unknown directive: =synopsis
- Around line 89:
Unknown directive: =description
- Around line 97:
Unknown directive: =inherits
- Around line 105:
Unknown directive: =method
- Around line 109:
Unknown directive: =signature
- Around line 113:
Unknown directive: =metadata
- Around line 153:
=cut found outside a pod block. Skipping to next block.
- Around line 175:
=cut found outside a pod block. Skipping to next block.
- Around line 185:
Unknown directive: =method
- Around line 191:
Unknown directive: =signature
- Around line 195:
Unknown directive: =metadata
- Around line 238:
=cut found outside a pod block. Skipping to next block.
- Around line 262:
=cut found outside a pod block. Skipping to next block.
- Around line 286:
=cut found outside a pod block. Skipping to next block.
- Around line 310:
=cut found outside a pod block. Skipping to next block.
- Around line 335:
=cut found outside a pod block. Skipping to next block.
- Around line 359:
=cut found outside a pod block. Skipping to next block.
- Around line 383:
=cut found outside a pod block. Skipping to next block.
- Around line 408:
=cut found outside a pod block. Skipping to next block.
- Around line 432:
=cut found outside a pod block. Skipping to next block.
- Around line 443:
Unknown directive: =method
- Around line 450:
Unknown directive: =signature
- Around line 454:
Unknown directive: =metadata
- Around line 484:
Unknown directive: =method
- Around line 490:
Unknown directive: =signature
- Around line 494:
Unknown directive: =metadata
- Around line 532:
Unknown directive: =method
- Around line 537:
Unknown directive: =signature
- Around line 541:
Unknown directive: =metadata
- Around line 571:
Unknown directive: =method
- Around line 575:
Unknown directive: =signature
- Around line 579:
Unknown directive: =metadata
- Around line 603:
Unknown directive: =method
- Around line 609:
Unknown directive: =signature
- Around line 613:
Unknown directive: =metadata
- Around line 651:
Unknown directive: =method
- Around line 655:
Unknown directive: =signature
- Around line 659:
Unknown directive: =metadata
- Around line 702:
=cut found outside a pod block. Skipping to next block.
- Around line 726:
=cut found outside a pod block. Skipping to next block.
- Around line 750:
=cut found outside a pod block. Skipping to next block.
- Around line 774:
=cut found outside a pod block. Skipping to next block.
- Around line 798:
=cut found outside a pod block. Skipping to next block.
- Around line 822:
=cut found outside a pod block. Skipping to next block.
- Around line 846:
=cut found outside a pod block. Skipping to next block.
- Around line 870:
=cut found outside a pod block. Skipping to next block.
- Around line 880:
Unknown directive: =method
- Around line 885:
Unknown directive: =signature
- Around line 889:
Unknown directive: =metadata
- Around line 932:
=cut found outside a pod block. Skipping to next block.
- Around line 956:
=cut found outside a pod block. Skipping to next block.
- Around line 980:
=cut found outside a pod block. Skipping to next block.
- Around line 1004:
=cut found outside a pod block. Skipping to next block.
- Around line 1028:
=cut found outside a pod block. Skipping to next block.
- Around line 1052:
=cut found outside a pod block. Skipping to next block.
- Around line 1076:
=cut found outside a pod block. Skipping to next block.
- Around line 1100:
=cut found outside a pod block. Skipping to next block.
- Around line 1110:
Unknown directive: =method
- Around line 1115:
Unknown directive: =signature
- Around line 1119:
Unknown directive: =metadata
- Around line 1162:
=cut found outside a pod block. Skipping to next block.
- Around line 1186:
=cut found outside a pod block. Skipping to next block.
- Around line 1210:
=cut found outside a pod block. Skipping to next block.
- Around line 1234:
=cut found outside a pod block. Skipping to next block.
- Around line 1258:
=cut found outside a pod block. Skipping to next block.
- Around line 1282:
=cut found outside a pod block. Skipping to next block.
- Around line 1306:
=cut found outside a pod block. Skipping to next block.
- Around line 1330:
=cut found outside a pod block. Skipping to next block.
- Around line 1340:
Unknown directive: =method
- Around line 1344:
Unknown directive: =signature
- Around line 1348:
Unknown directive: =metadata
- Around line 1391:
=cut found outside a pod block. Skipping to next block.
- Around line 1415:
=cut found outside a pod block. Skipping to next block.
- Around line 1439:
=cut found outside a pod block. Skipping to next block.
- Around line 1463:
=cut found outside a pod block. Skipping to next block.
- Around line 1487:
=cut found outside a pod block. Skipping to next block.
- Around line 1511:
=cut found outside a pod block. Skipping to next block.
- Around line 1535:
=cut found outside a pod block. Skipping to next block.
- Around line 1559:
=cut found outside a pod block. Skipping to next block.
- Around line 1569:
Unknown directive: =method
- Around line 1574:
Unknown directive: =signature
- Around line 1578:
Unknown directive: =metadata
- Around line 1621:
=cut found outside a pod block. Skipping to next block.
- Around line 1645:
=cut found outside a pod block. Skipping to next block.
- Around line 1669:
=cut found outside a pod block. Skipping to next block.
- Around line 1693:
=cut found outside a pod block. Skipping to next block.
- Around line 1717:
=cut found outside a pod block. Skipping to next block.
- Around line 1741:
=cut found outside a pod block. Skipping to next block.
- Around line 1765:
=cut found outside a pod block. Skipping to next block.
- Around line 1789:
=cut found outside a pod block. Skipping to next block.
- Around line 1799:
Unknown directive: =method
- Around line 1804:
Unknown directive: =signature
- Around line 1808:
Unknown directive: =metadata
- Around line 1851:
=cut found outside a pod block. Skipping to next block.
- Around line 1875:
=cut found outside a pod block. Skipping to next block.
- Around line 1899:
=cut found outside a pod block. Skipping to next block.
- Around line 1923:
=cut found outside a pod block. Skipping to next block.
- Around line 1947:
=cut found outside a pod block. Skipping to next block.
- Around line 1971:
=cut found outside a pod block. Skipping to next block.
- Around line 1995:
=cut found outside a pod block. Skipping to next block.
- Around line 2019:
=cut found outside a pod block. Skipping to next block.
- Around line 2029:
Unknown directive: =method
- Around line 2033:
Unknown directive: =signature
- Around line 2037:
Unknown directive: =metadata
- Around line 2080:
=cut found outside a pod block. Skipping to next block.
- Around line 2104:
=cut found outside a pod block. Skipping to next block.
- Around line 2128:
=cut found outside a pod block. Skipping to next block.
- Around line 2152:
=cut found outside a pod block. Skipping to next block.
- Around line 2176:
=cut found outside a pod block. Skipping to next block.
- Around line 2200:
=cut found outside a pod block. Skipping to next block.
- Around line 2224:
=cut found outside a pod block. Skipping to next block.
- Around line 2248:
=cut found outside a pod block. Skipping to next block.
- Around line 2258:
Unknown directive: =method
- Around line 2262:
Unknown directive: =signature
- Around line 2266:
Unknown directive: =metadata
- Around line 2309:
=cut found outside a pod block. Skipping to next block.
- Around line 2333:
=cut found outside a pod block. Skipping to next block.
- Around line 2357:
=cut found outside a pod block. Skipping to next block.
- Around line 2381:
=cut found outside a pod block. Skipping to next block.
- Around line 2405:
=cut found outside a pod block. Skipping to next block.
- Around line 2429:
=cut found outside a pod block. Skipping to next block.
- Around line 2453:
=cut found outside a pod block. Skipping to next block.
- Around line 2477:
=cut found outside a pod block. Skipping to next block.
- Around line 2487:
Unknown directive: =method
- Around line 2491:
Unknown directive: =signature
- Around line 2495:
Unknown directive: =metadata
- Around line 2513:
=cut found outside a pod block. Skipping to next block.
- Around line 2534:
=cut found outside a pod block. Skipping to next block.
- Around line 2555:
=cut found outside a pod block. Skipping to next block.
- Around line 2566:
Unknown directive: =method
- Around line 2571:
Unknown directive: =signature
- Around line 2575:
Unknown directive: =metadata
- Around line 2603:
Unknown directive: =method
- Around line 2608:
Unknown directive: =signature
- Around line 2612:
Unknown directive: =metadata
- Around line 2642:
Unknown directive: =operator
- Around line 2658:
=cut found outside a pod block. Skipping to next block.
- Around line 2668:
Unknown directive: =method
- Around line 2673:
Unknown directive: =signature
- Around line 2677:
Unknown directive: =metadata
- Around line 2720:
=cut found outside a pod block. Skipping to next block.
- Around line 2744:
=cut found outside a pod block. Skipping to next block.
- Around line 2768:
=cut found outside a pod block. Skipping to next block.
- Around line 2792:
=cut found outside a pod block. Skipping to next block.
- Around line 2816:
=cut found outside a pod block. Skipping to next block.
- Around line 2840:
=cut found outside a pod block. Skipping to next block.
- Around line 2864:
=cut found outside a pod block. Skipping to next block.
- Around line 2888:
=cut found outside a pod block. Skipping to next block.
- Around line 2898:
Unknown directive: =partials