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


Manual Reference Pages  -  FUNCTION::PARAMETERS::INFO (3)

.ds Aq ’

NAME

Function::Parameters::Info - Information about parameter lists

CONTENTS

SYNOPSIS



  use Function::Parameters;
 
  fun foo($x, $y, :$hello, :$world = undef) {}
 
  my $info = Function::Parameters::info \&foo;
  my $p0 = $info->invocant;             # undef
  my @p1 = $info->positional_required;  # ($x, $y)
  my @p2 = $info->positional_optional;  # ()
  my @p3 = $info->named_required;       # ($hello)
  my @p4 = $info->named_optional;       # ($world)
  my $p5 = $info->slurpy;               # undef
  my $min = $info->args_min;  # 4
  my $max = $info->args_max;  # inf
 
  my $invocant = Function::Parameters::info(method () { 42 })->invocant;  # $self
 
  my $slurpy = Function::Parameters::info(fun {})->slurpy;  # @_



DESCRIPTION

Function::Parameters::info returns objects of this class to describe parameter lists of functions. The following methods are available:

CW$info->invocant

Returns the name of the variable into which the first argument is shifted automatically, or undef if no such thing exists. This will usually return $self for methods.

CW$info->positional_required

Returns a list of the names of the required positional parameters (or a count in scalar context).

CW$info->positional_optional

Returns a list of the names of the optional positional parameters (or a count in scalar context).

CW$info->named_required

Returns a list of the names of the required named parameters (or a count in scalar context).

CW$info->named_optional

Returns a list of the names of the optional named parameters (or a count in scalar context).

CW$info->slurpy

Returns the name of the final array or hash that gobbles up all remaining arguments, or undef if no such thing exists.

As a special case, functions defined without an explicit parameter list (i.e. without ( )) will return @_ here because they accept any number of arguments.

CW$info->args_min

Returns the minimum number of arguments this function requires. This is computed as follows: Invocant and required positional parameters count 1 each. Optional parameters don’t count. Required named parameters count 2 each (key + value). Slurpy parameters don’t count either because they accept empty lists.

CW$info->args_max

Returns the maximum number of arguments this function accepts. This is computed as follows: If there is any named or slurpy parameter, the result is Inf. Otherwise the result is the sum of all invocant and positional parameters.

    Experimental feature: Types

All the methods described above actually return parameter objects wherever the description says name. These objects have two methods: name, which returns the name of the parameter (as a plain string), and type, which returns the corresponding type constraint object (or undef if there was no type specified).

This should be invisible if you don’t use types because the objects also overload stringification to call name. That is, if you treat parameter objects like strings, they behave like strings (i.e. their names).

SEE ALSO

Function::Parameters

AUTHOR

Lukas Mai, <l.mai at web.de>

COPYRIGHT & LICENSE

Copyright 2013 Lukas Mai.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 FUNCTION::PARAMETERS::INFO (3) 2016-02-13

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.