Change Constant(undef) error to something meaningful
authorFather Chrysostomos <sprout@cpan.org>
Fri, 7 Dec 2012 17:25:49 +0000 (09:25 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 9 Dec 2012 02:46:52 +0000 (18:46 -0800)
commitbb4784f001b7eefaf06670e2ee209e9ea942d5af
treec29c7a475f0e0d358d0064afc0fbd3ee9ad07cb7
parent247a7f40cd18f049b85ee008433addbd3069717a
Change Constant(undef) error to something meaningful

Look at these errors:

$ perl5.16.0 -e 'use overload; BEGIN{overload::constant q => sub{}; } "aaa"'
Constant(q): Call to &{$^H{q}} did not return a defined value at -e line 1, near "} "aaa""
Execution of -e aborted due to compilation errors.

$ perl5.16.0 -e 'BEGIN{++$_ for @INC{<charnames.pm _charnames.pm>}} "\N{a}"'
Constant(\N{a}) unknown at -e line 1, within string
Execution of -e aborted due to compilation errors.

$ perl5.16.0 -e 'use overload; BEGIN{overload::constant q => sub{}; } tr"aaa""'
Constant(tr): Call to &{$^H{q}} did not return a defined value at -e line 1, within string
Execution of -e aborted due to compilation errors.

The (q) and (tr) might seem a bit odd, but are not completely meaning-
less.  They match the third argument passed to the overload handler.
Now look at this:

$ perl5.16.0 -e 'use overload; BEGIN{overload::constant integer => sub{}; } 123'
Constant(undef): Call to &{$^H{integer}} did not return a defined value at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

$ perl5.16.0 -e 'use overload; BEGIN{overload::constant float => sub{}; } 1.23'
Constant(undef): Call to &{$^H{float}} did not return a defined value at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

$ perl5.16.0 -e 'use overload; BEGIN{overload::constant binary => sub{}; } 0x123'
Constant(undef): Call to &{$^H{binary}} did not return a defined value at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

That Constant(undef) is not helpful.  This commit changes it to show
the number itself, making these cases similar to \N{}.
t/lib/croak/toke
toke.c