mauke / Function-Parameters

Function::Parameters - define functions and methods with parameter lists ("subroutine signatures")
https://metacpan.org/pod/Function::Parameters
18 stars 19 forks source link

Function::Parameters::info does not get default values of optional arguments #38

Closed iynehz closed 1 year ago

iynehz commented 5 years ago

Looks like now it can get only the arguments names, but not defualt values in case of optional argument. I would be interested in having that feature. For example, it can be used to generate from a function a string for its complete function signature, which can be used in automatic generating the function's doc POD, useful in mid-to-large scale projects.

mauke commented 1 year ago

The problem is that default arguments are expressions, not values. When you do something like

fun foo($x = bar()) {}
foo(42);

, the bar() expression is never evaluated (since the default argument is not used) and bar is never called. The only thing you could potentially get is the source code of the expression in string form, but I'm not sure how I'd even do that. F:P doesn't know how long a default argument is or where it ends; it just calls back into the perl parser, which consumes an unpredictable amount of source code and returns an optree fragment.