PDL::NDBin::Action::CodeRef - Action for PDL::NDBin that calls user sub
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).
my $instance = PDL::NDBin::Action::CodeRef->new( N => $N, coderef => $coderef, type => double, # optional );
Construct an instance for this action. Accepts three parameters:
The number of bins. Required.
A reference to an anonymous or named subroutine that implements the real action. Required.
The type of the output variable. Optional. Defaults to the type of the variable this instance is associated with.
$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.
my $result = $instance->result;
Return the result of the computation.
Edward Baudrez <email@example.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 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.