NAME
Getopt::EX::Func - Function call interface
SYNOPSIS
use Getopt::EX::Func qw(parse_func);
my $func = parse_func(...);
$func->call;
DESCRIPTION
This module provides a way to create function call objects used in the Getopt::EX module set.
If your script has a --begin option which tells the script to call a specific function at the beginning of execution, you can do it like this:
use Getopt::EX::Func qw(parse_func);
GetOptions("begin:s" => $opt_begin);
my $func = parse_func($opt_begin);
$func->call;
Then the script can be invoked like this:
% example -Mfoo --begin 'repeat(debug,msg=hello,count=2)'
In this example, the function repeat should be declared in module foo or in a startup rc file such as ~/.examplerc. The actual function call is performed in this way:
repeat ( debug => 1, msg => 'hello', count => '2' );
As you can see, arguments in the function call string are passed in name => value style. Parameters without a value (debug in this example) are assigned the value 1.
Function itself can be implemented like this:
    our @EXPORT = qw(repeat);
    sub repeat {
	my %opt = @_;
	print Dumper \%opt if $opt{debug};
	for (1 .. $opt{count}) {
	    say $opt{msg};
	}
    }
It is also possible to declare the function inline:
% example -Mfoo --begin 'sub{ say "wahoo!!" }'
The function say can be used because the function is executed under a use v5.14 context.