LanX has asked for the wisdom of the Perl Monks concerning the following question:
Is there already any project on CPAN which parses the optree in the CHECK phase?
please refer to this demo code
package TEST; # The Class sub new { bless {}, $_[0] } sub bla { warn "Bla called" } package main; CHECK { warn B::Deparse->new()->coderef2text(\&tst); } use strict; use warnings; use Data::Dump qw/pp dd/; use B::Deparse; sub tst { my TEST $x; # Typing $x = TEST->new() ; $x->blo(); # Typo } tst();
output
{ use warnings; use strict; my TEST $x; $x = 'TEST'->new; $x->blo; } at d:/exp/deparse_type.pl line 11. Can't locate object method "blo" via package "TEST" at d:/exp/deparse_ +type.pl line 23.
the wrong method call ->blo is only caught at run-time yet while B::Deparse shows that all informations are already available in the op-tree after voluntary typing.
Please spare me with comments like "This is unperlish", my colleagues are propagating a far worse solution with exported constants to catch typos.
$x->$blo
$blo would be caught by strict because it's not predefined like $bla="bla" .
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: compiletime checking of valid method calls
by choroba (Cardinal) on Apr 08, 2019 at 16:03 UTC | |
by LanX (Saint) on Apr 08, 2019 at 16:10 UTC | |
|
Re: compiletime checking of valid method calls
by Veltro (Hermit) on Apr 08, 2019 at 22:22 UTC | |
by LanX (Saint) on Apr 08, 2019 at 22:56 UTC |