I got the requirement to check at compile time if a method call is valid.

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


In reply to compiletime checking of valid method calls by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.