NAME
PDL::NDBin::Action::CodeRef - Action for PDL::NDBin that calls user sub
VERSION
version 0.028
DESCRIPTION
This class implements a special action for PDL::NDBin that is actually a wrapper around a user-defined function. This class exists just to fit user-defined subroutines in the same framework as the other actions, which are defined by classes (so that the user doesn't have to define a full-blown class just to implement an action).
METHODS
new()
my $instance = PDL::NDBin::Action::CodeRef->new(
N => $N,
coderef => $coderef,
type => double, # optional
);
Construct an instance for this action. Accepts three parameters:
- N
-
The number of bins. Required.
- coderef
-
A reference to an anonymous or named subroutine that implements the real action. Required.
- type
-
The type of the output variable. Optional. Defaults to the type of the variable this instance is associated with.
process()
$instance->process( $iter );
Run the action with the given iterator $iter. This action cannot assume that all bins can be computed at once, and will not deactivate the variable. This means that process() will need to be called for every bin.
Note that process() does not trap exceptions. The user-supplied subroutine should be wrapped in an eval block if the rest of the code should be protected from exceptions raised inside the subroutine.
result()
my $result = $instance->result;
Return the result of the computation.
AUTHOR
Edward Baudrez <ebaudrez@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by Edward Baudrez.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.