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: 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 code data.
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(Str $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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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) (Bool)
{ 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 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) (Bool)
{ 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: pdml: authors t/Venus.t: pdml: license
147 POD Errors
The following errors were encountered while parsing the POD:
- Around line 13:
Unknown directive: =name
- Around line 21:
Unknown directive: =tagline
- Around line 29:
Unknown directive: =abstract
- Around line 37:
Unknown directive: =includes
- Around line 62:
Unknown directive: =synopsis
- Around line 87:
Unknown directive: =description
- Around line 95:
Unknown directive: =inherits
- Around line 103:
Unknown directive: =method
- Around line 107:
Unknown directive: =signature
- Around line 111:
Unknown directive: =metadata
- Around line 151:
=cut found outside a pod block. Skipping to next block.
- Around line 173:
=cut found outside a pod block. Skipping to next block.
- Around line 183:
Unknown directive: =method
- Around line 189:
Unknown directive: =signature
- Around line 193:
Unknown directive: =metadata
- Around line 236:
=cut found outside a pod block. Skipping to next block.
- Around line 260:
=cut found outside a pod block. Skipping to next block.
- Around line 284:
=cut found outside a pod block. Skipping to next block.
- Around line 308:
=cut found outside a pod block. Skipping to next block.
- Around line 333:
=cut found outside a pod block. Skipping to next block.
- Around line 357:
=cut found outside a pod block. Skipping to next block.
- Around line 381:
=cut found outside a pod block. Skipping to next block.
- Around line 406:
=cut found outside a pod block. Skipping to next block.
- Around line 430:
=cut found outside a pod block. Skipping to next block.
- Around line 441:
Unknown directive: =method
- Around line 448:
Unknown directive: =signature
- Around line 452:
Unknown directive: =metadata
- Around line 482:
Unknown directive: =method
- Around line 488:
Unknown directive: =signature
- Around line 492:
Unknown directive: =metadata
- Around line 530:
Unknown directive: =method
- Around line 535:
Unknown directive: =signature
- Around line 539:
Unknown directive: =metadata
- Around line 569:
Unknown directive: =method
- Around line 573:
Unknown directive: =signature
- Around line 577:
Unknown directive: =metadata
- Around line 601:
Unknown directive: =method
- Around line 607:
Unknown directive: =signature
- Around line 611:
Unknown directive: =metadata
- Around line 649:
Unknown directive: =method
- Around line 653:
Unknown directive: =signature
- Around line 657:
Unknown directive: =metadata
- Around line 700:
=cut found outside a pod block. Skipping to next block.
- Around line 724:
=cut found outside a pod block. Skipping to next block.
- Around line 748:
=cut found outside a pod block. Skipping to next block.
- Around line 772:
=cut found outside a pod block. Skipping to next block.
- Around line 796:
=cut found outside a pod block. Skipping to next block.
- Around line 820:
=cut found outside a pod block. Skipping to next block.
- Around line 844:
=cut found outside a pod block. Skipping to next block.
- Around line 868:
=cut found outside a pod block. Skipping to next block.
- Around line 878:
Unknown directive: =method
- Around line 883:
Unknown directive: =signature
- Around line 887:
Unknown directive: =metadata
- Around line 930:
=cut found outside a pod block. Skipping to next block.
- Around line 954:
=cut found outside a pod block. Skipping to next block.
- Around line 978:
=cut found outside a pod block. Skipping to next block.
- Around line 1002:
=cut found outside a pod block. Skipping to next block.
- Around line 1026:
=cut found outside a pod block. Skipping to next block.
- Around line 1050:
=cut found outside a pod block. Skipping to next block.
- Around line 1074:
=cut found outside a pod block. Skipping to next block.
- Around line 1098:
=cut found outside a pod block. Skipping to next block.
- Around line 1108:
Unknown directive: =method
- Around line 1113:
Unknown directive: =signature
- Around line 1117:
Unknown directive: =metadata
- Around line 1160:
=cut found outside a pod block. Skipping to next block.
- Around line 1184:
=cut found outside a pod block. Skipping to next block.
- Around line 1208:
=cut found outside a pod block. Skipping to next block.
- Around line 1232:
=cut found outside a pod block. Skipping to next block.
- Around line 1256:
=cut found outside a pod block. Skipping to next block.
- Around line 1280:
=cut found outside a pod block. Skipping to next block.
- Around line 1304:
=cut found outside a pod block. Skipping to next block.
- Around line 1328:
=cut found outside a pod block. Skipping to next block.
- Around line 1338:
Unknown directive: =method
- Around line 1342:
Unknown directive: =signature
- Around line 1346:
Unknown directive: =metadata
- Around line 1389:
=cut found outside a pod block. Skipping to next block.
- Around line 1413:
=cut found outside a pod block. Skipping to next block.
- Around line 1437:
=cut found outside a pod block. Skipping to next block.
- Around line 1461:
=cut found outside a pod block. Skipping to next block.
- Around line 1485:
=cut found outside a pod block. Skipping to next block.
- Around line 1509:
=cut found outside a pod block. Skipping to next block.
- Around line 1533:
=cut found outside a pod block. Skipping to next block.
- Around line 1557:
=cut found outside a pod block. Skipping to next block.
- Around line 1567:
Unknown directive: =method
- Around line 1572:
Unknown directive: =signature
- Around line 1576:
Unknown directive: =metadata
- Around line 1619:
=cut found outside a pod block. Skipping to next block.
- Around line 1643:
=cut found outside a pod block. Skipping to next block.
- Around line 1667:
=cut found outside a pod block. Skipping to next block.
- Around line 1691:
=cut found outside a pod block. Skipping to next block.
- Around line 1715:
=cut found outside a pod block. Skipping to next block.
- Around line 1739:
=cut found outside a pod block. Skipping to next block.
- Around line 1763:
=cut found outside a pod block. Skipping to next block.
- Around line 1787:
=cut found outside a pod block. Skipping to next block.
- Around line 1797:
Unknown directive: =method
- Around line 1802:
Unknown directive: =signature
- Around line 1806:
Unknown directive: =metadata
- Around line 1849:
=cut found outside a pod block. Skipping to next block.
- Around line 1873:
=cut found outside a pod block. Skipping to next block.
- Around line 1897:
=cut found outside a pod block. Skipping to next block.
- Around line 1921:
=cut found outside a pod block. Skipping to next block.
- Around line 1945:
=cut found outside a pod block. Skipping to next block.
- Around line 1969:
=cut found outside a pod block. Skipping to next block.
- Around line 1993:
=cut found outside a pod block. Skipping to next block.
- Around line 2017:
=cut found outside a pod block. Skipping to next block.
- Around line 2027:
Unknown directive: =method
- Around line 2031:
Unknown directive: =signature
- Around line 2035:
Unknown directive: =metadata
- Around line 2078:
=cut found outside a pod block. Skipping to next block.
- Around line 2102:
=cut found outside a pod block. Skipping to next block.
- Around line 2126:
=cut found outside a pod block. Skipping to next block.
- Around line 2150:
=cut found outside a pod block. Skipping to next block.
- Around line 2174:
=cut found outside a pod block. Skipping to next block.
- Around line 2198:
=cut found outside a pod block. Skipping to next block.
- Around line 2222:
=cut found outside a pod block. Skipping to next block.
- Around line 2246:
=cut found outside a pod block. Skipping to next block.
- Around line 2256:
Unknown directive: =method
- Around line 2260:
Unknown directive: =signature
- Around line 2264:
Unknown directive: =metadata
- Around line 2307:
=cut found outside a pod block. Skipping to next block.
- Around line 2331:
=cut found outside a pod block. Skipping to next block.
- Around line 2355:
=cut found outside a pod block. Skipping to next block.
- Around line 2379:
=cut found outside a pod block. Skipping to next block.
- Around line 2403:
=cut found outside a pod block. Skipping to next block.
- Around line 2427:
=cut found outside a pod block. Skipping to next block.
- Around line 2451:
=cut found outside a pod block. Skipping to next block.
- Around line 2475:
=cut found outside a pod block. Skipping to next block.
- Around line 2485:
Unknown directive: =method
- Around line 2490:
Unknown directive: =signature
- Around line 2494:
Unknown directive: =metadata
- Around line 2522:
Unknown directive: =method
- Around line 2527:
Unknown directive: =signature
- Around line 2531:
Unknown directive: =metadata
- Around line 2561:
Unknown directive: =operator
- Around line 2577:
=cut found outside a pod block. Skipping to next block.
- Around line 2587:
Unknown directive: =method
- Around line 2592:
Unknown directive: =signature
- Around line 2596:
Unknown directive: =metadata
- Around line 2639:
=cut found outside a pod block. Skipping to next block.
- Around line 2663:
=cut found outside a pod block. Skipping to next block.
- Around line 2687:
=cut found outside a pod block. Skipping to next block.
- Around line 2711:
=cut found outside a pod block. Skipping to next block.
- Around line 2735:
=cut found outside a pod block. Skipping to next block.
- Around line 2759:
=cut found outside a pod block. Skipping to next block.
- Around line 2783:
=cut found outside a pod block. Skipping to next block.
- Around line 2807:
=cut found outside a pod block. Skipping to next block.
- Around line 2817:
Unknown directive: =partials