GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::Object::Code(3) User Contributed Perl Documentation Data::Object::Code(3)

Data::Object::Code

Code Class for Perl 5

  package main;

  use Data::Object::Code;

  my $code = Data::Object::Code->new(sub { $_[0] + 1 });

This package provides methods for manipulating code data.

This package inherits behaviors from:

Data::Object::Kind

This package integrates behaviors from:

Data::Object::Role::Dumpable

Data::Object::Role::Proxyable

Data::Object::Role::Throwable

This package uses type constraints from:

Data::Object::Types

This package implements the following methods:

  call(Any $arg1) : Any

The call method executes and returns the result of the code.

call example #1
  my $code = Data::Object::Code->new(sub { ($_[0] // 0) + 1 });

  $code->call; # 1
    
call example #2
  my $code = Data::Object::Code->new(sub { ($_[0] // 0) + 1 });

  $code->call(0); # 1
    
call example #3
  my $code = Data::Object::Code->new(sub { ($_[0] // 0) + 1 });

  $code->call(1); # 2
    
call example #4
  my $code = Data::Object::Code->new(sub { ($_[0] // 0) + 1 });

  $code->call(2); # 3
    

  compose(CodeRef $arg1, Any $arg2) : CodeLike

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 example #1
  my $code = Data::Object::Code->new(sub { [@_] });

  $code->compose($code, 1,2,3);

  # $code->(4,5,6); # [[1,2,3,4,5,6]]
    

  conjoin(CodeRef $arg1) : CodeLike

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 example #1
  my $code = Data::Object::Code->new(sub { $_[0] % 2 });

  $code = $code->conjoin(sub { 1 });

  # $code->(0); # 0
  # $code->(1); # 1
  # $code->(2); # 0
  # $code->(3); # 1
  # $code->(4); # 0
    

  curry(CodeRef $arg1) : CodeLike

The curry method returns a code reference which executes the code passing it the arguments and any additional parameters when executed.

curry example #1
  my $code = Data::Object::Code->new(sub { [@_] });

  $code = $code->curry(1,2,3);

  # $code->(4,5,6); # [1,2,3,4,5,6]
    

  defined() : Num

The defined method returns true if the object represents a value that meets the criteria for being defined, otherwise it returns false.

defined example #1
  my $code = Data::Object::Code->new;

  $code->defined; # 1
    

  disjoin(CodeRef $arg1) : CodeRef

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 example #1
  my $code = Data::Object::Code->new(sub { $_[0] % 2 });

  $code = $code->disjoin(sub { -1 });

  # $code->(0); # -1
  # $code->(1); #  1
  # $code->(2); # -1
  # $code->(3); #  1
  # $code->(4); # -1
    

  next(Any $arg1) : Any

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 example #1
  my $code = Data::Object::Code->new(sub { $_[0] * 2 });

  $code->next(72); # 144
    

  rcurry(Any $arg1) : CodeLike

The rcurry method returns a code reference which executes the code passing it the any additional parameters and any arguments when executed.

rcurry example #1
  my $code = Data::Object::Code->new(sub { [@_] });

  $code = $code->rcurry(1,2,3);

  # $code->(4,5,6); # [4,5,6,1,2,3]
    

Al Newkirk, "awncorp@cpan.org"

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file" <https://github.com/iamalnewkirk/data-object/blob/master/LICENSE>.

Wiki <https://github.com/iamalnewkirk/data-object/wiki>

Project <https://github.com/iamalnewkirk/data-object>

Initiatives <https://github.com/iamalnewkirk/data-object/projects>

Milestones <https://github.com/iamalnewkirk/data-object/milestones>

Contributing <https://github.com/iamalnewkirk/data-object/blob/master/CONTRIBUTE.md>

Issues <https://github.com/iamalnewkirk/data-object/issues>

2020-04-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.