develooper Front page | perl.perl5.porters | Postings from August 2022

Re: Pre-RFC: A Metaprogramming (Reflection and Introspection) API

Thread Previous | Thread Next
Paul "LeoNerd" Evans
August 30, 2022 10:24
Re: Pre-RFC: A Metaprogramming (Reflection and Introspection) API
Message ID:
On Mon, 29 Aug 2022 16:28:32 -0300
breno <> wrote:

> On Fri, Aug 26, 2022 at 2:30 PM Paul "LeoNerd" Evans
> <> wrote:
> > Plus I'm open to the idea I may still have missed some useful
> > abilities. The point of the RFC is not to create a fully-exhaustive
> > list, but to create the module with enough useful pieces to begin
> > with, in the hope that more will be added over time as the need
> > becomes apparent.
> >  
> Given a subroutine declaration with signatures, I'd love to be able
> to at least see
> variable names, "types" and defaults. I am unaware of any way to do
> it, and I think it
> would be good for auto-documentation and code completion within
> editors.

Seeing the names isn't too bad; it's just an inspection of the pad.

Don't forget though that defaults come from expressions, not mere

  sub f($x, $y = lc($x), $z = substr($y, 0, 5)) { ... }

Here, it would be easy to say that:

  * min arity is 1
  * max arity is 3
  * parameter names are qw( $x $y $z )

but there isn't a simple representation for the defaults.

> If a sub is called, I'd love to be able to easily inspect the name of
> the variables passed to it.
> Padwalker does it with var_name() but only to a certain extent (must
> be refs, not copies, etc).
> This is one of the most requested features in Data::Printer.

I'm not quite sure I follow this part of the request. Maybe an example?
Show a small program and what output you'd like to see.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About