I want to know how to force the resolution of subs at compile time.
For some background, with perl, I can resolve package symbols strictly at compile-time using a ::
affixed to the end of the package name. For example.
perl -wE'use warnings FATAL => "bareword"; die 7; Foo::; die 42'
Bareword "Foo::" refers to nonexistent package at -e line 1.
You'll notice in the above code, we didn't die with 7 or 42. We died before the run-time phase. This only works to resolve the package name. I can use a method resolution operator (->
) with the above syntax and resolve a function name in run-time,
perl -E'use warnings FATAL => "bareword"; die 7; Foo::->bar(); die 42'
Bareword "Foo::" refers to nonexistent package at -e line 1.
But this isn't exactly what I want,
If I declare a package
Foo
that lacks a subbar
and I want to call the non-existent functionbar
inside that package, I will no longer get a compile-time error,perl -E'package Foo {}; use warnings FATAL => "bareword"; die 7; Foo::->bar(); die 42' 7 at -e line 1.
You can see here, when
()
is affixed to the end of the symbol it resolves in run-time; but, when::
is affixed to the end of a symbol though it's assumed to be a package name it's resolved in compile-time.The
->
operator is using run-time method resolution. It searches@ISA
, and also provides a first argument of the class.
What I would like is to die if Foo
doesn't have bar
sub in compile-time.