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
Getopt::EX::Func(3) User Contributed Perl Documentation Getopt::EX::Func(3)

Getopt::EX::Func - Function call interface

  use Getopt::EX::Func qw(parse_func);

  my $func = parse_func(...);

  $func->call;

This module provides the way to create function call object used in Getopt::EX module set.

If your script has --begin option which tells the script to call 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 script can be invoked like this:

    % example -Mfoo --begin 'repeat(debug,msg=hello,count=2)'

In this example, function "repeat" should be declared in module "foo" or in start up rc file such as ~/.examplerc. Actual function call is done in this way:

    repeat ( debug => 1, msg => 'hello', count => '2' );

As you can notice, arguments in the function call string is passed in name => value style. Parameter without value ("debug" in this example) is assigned 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 in-line:

    % example -Mfoo --begin 'sub{ say "wahoo!!" }'

Function "say" can be used because the function is executed under "use v5.14" context.

2019-09-03 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.