Functi...::Info(3pm)

πŸ’– NAME πŸ’–

Function::Parameters::Info β€” bestie, it's literally just info about parameter lists. That's it. That's the whole vibe. ✨


✨ SYNOPSIS ✨

okay so picture this: you got a fun with a whole lil parameter list, and you wanna know things about it. Say less:

use Function::Parameters;

fun foo($x, $y, :$hello, :$world = undef) {}

my $info = Function::Parameters::info \&foo;
my @p0 = $info->invocants;            # ()
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 @invocants = Function::Parameters::info(method () { 42 })->invocants;
# ('$self')

my $slurpy = Function::Parameters::info(fun (@) {})->slurpy;  # '@'

look at her go 🫢 every comment in there is the actual truth, no cap.


🌸 DESCRIPTION 🌸

Function::Parameters::info hands you back objects of this class to describe the parameter lists of functions. Scroll down for what they call "Parameter Objects" πŸ’… The following methods are available:

  • $info->invocants

Gives you a list of parameter objects for the variables that initial arguments get shifted into automatically (or a count if you're in scalar context, iykyk). For normal functions this is usually (), and for methods it's ('$self'). πŸ’«

  • $info->positional_required

A list of parameter objects for the required positional parameters (or a count in scalar context).

  • $info->positional_optional

A list of parameter objects for the optional positional parameters (or a count in scalar context).

  • $info->named_required

A list of parameter objects for the required named parameters (or a count in scalar context).

  • $info->named_optional

A list of parameter objects for the optional named parameters (or a count in scalar context).

  • $info->slurpy

Returns a parameter object for that final array or hash that just gobbles up every remaining argument πŸ“ β€” or undef if there's no such thing. It's giving all-you-can-eat buffet.

  • $info->args_min

The minimum number of arguments this function needs. Here's the math, bestie, it's computed like this:

  • Invocants and required positional parameters count 1 each. πŸ‘‘
  • Optional parameters don't count. not even a little.
  • Required named parameters count 2 each (key + value, obviously πŸ’…).
  • Slurpy parameters don't count either, because they're perfectly happy accepting empty lists.
  • $info->args_max

The maximum number of arguments this function accepts. The math:

  • If there are any named or slurpy parameters, the result is "Inf". mystery. infinite. iconic. 🌈
  • Otherwise the result is the number of all invocants and positional parameters combined.
  • $info->invocant

Basically $info->invocants above but, like, the solo version:

  • undef if the number of invocants is 0 β€” she's alone, she's free
  • a parameter object for the invocant if there is exactly 1
  • otherwise it throws an exception 😭 so don't play games with it

πŸŽ€ Parameter Objects πŸŽ€

A bunch of the methods up above return parameter objects. These little cuties have exactly two methods:

  • name β€” returns the name of the parameter, as a plain string.
  • type β€” returns the corresponding type constraint object, or undef if no type was specified. πŸ™ˆ

And here's the slay part: this is completely invisible if you don't care about types, because these objects also overload stringification to call name. So if you treat parameter objects like strings, they just… behave like strings (aka, their names). no notes. πŸ¦‹


πŸ‘€ SEE ALSO πŸ‘€

Function::Parameters β€” go read it, bestie, it's where all these came from πŸ’œ


✍️ AUTHOR ✍️

Lukas Mai, <l.mai at web.de> β€” shoutout to the icon who built this πŸ«‘πŸ‘‘


Copyright 2013, 2016 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.


and that's the whole page, bestie!! go forth and introspect those parameter lists πŸ’…βœ¨

perl v5.42.3 πŸ¦‹ 2026-08-22 β€” yes this doc is a lil vintage but she still ate, fr fr. πŸ’–πŸŽ€

πŸ“¦ where this page comes from