NAME
Sub::Apply - apply arguments to proc.
SYNOPSIS
use Sub::Apply qw(apply apply_if);
{
my $procname = 'sum';
my $sum = apply( $procname, 1, 2, 3);
}
{
my $procname = 'sum';
my $sum = apply_if( $procname, 1, 2, 3);
# not die if $procname does not exist.
}
DESCRIPTION
Sub::Apply provides function apply
and apply_if
. This function apply arguments to proc.
This module is designed for function call. If you want to call class method or instance method, I recommend you to use UNIVERSAL#can
.
EXPORT_OK
apply, apply_if
FUNCTION
apply($procname, @args)
Apply @args to $procname. If you want to call function that not in current package, you do like below.
apply('Foo::sum', 1, 2)
This method looks up a function using symbol table and call it. But this function DOES NOT USE @ISA to look up. This behavior is same as perl funciton call style.
apply_if($procname, @args)
Same as apply. But apply_if does not die unless $procname does not exist.
You can set $Sub::Apply::WARNING=1
for debugging.
WARNING
apply
and apply_if
cannot call CORE functions.
AUTHOR
Yoshihiro Sasaki, <ysasaki at cpan.org<gt>
COPYRIGHT AND LICENSE
Copyright (C) 2011 by Yoshihiro Sasaki
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.