diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-12-07 09:25:49 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-12-08 18:46:52 -0800 |
commit | bb4784f001b7eefaf06670e2ee209e9ea942d5af (patch) | |
tree | c29c7a475f0e0d358d0064afc0fbd3ee9ad07cb7 /t | |
parent | 247a7f40cd18f049b85ee008433addbd3069717a (diff) | |
download | perl-bb4784f001b7eefaf06670e2ee209e9ea942d5af.tar.gz |
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{}.
Diffstat (limited to 't')
-rw-r--r-- | t/lib/croak/toke | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/t/lib/croak/toke b/t/lib/croak/toke index cd1fc2023c..329e12ce66 100644 --- a/t/lib/croak/toke +++ b/t/lib/croak/toke @@ -33,7 +33,7 @@ use overload; BEGIN { overload::constant integer => sub {}; undef *^H } 1 EXPECT -Constant(undef) unknown at - line 3, at end of line +Constant(1) unknown at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME Float constant overloading returning undef @@ -41,7 +41,7 @@ use overload; BEGIN { overload::constant float => sub {}; undef *^H } 1.1 EXPECT -Constant(undef) unknown at - line 3, at end of line +Constant(1.1) unknown at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME Binary constant overloading returning undef @@ -49,7 +49,7 @@ use overload; BEGIN { overload::constant binary => sub {}; undef *^H } 0x1 EXPECT -Constant(undef) unknown at - line 3, at end of line +Constant(0x1) unknown at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME String constant overloading returning undef @@ -84,7 +84,7 @@ use overload; BEGIN { overload::constant integer => sub {} } 1 EXPECT -Constant(undef): Call to &{$^H{integer}} did not return a defined value at - line 3, at end of line +Constant(1): Call to &{$^H{integer}} did not return a defined value at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME Float constant overloading returning undef @@ -92,7 +92,7 @@ use overload; BEGIN { overload::constant float => sub {} } 1.1 EXPECT -Constant(undef): Call to &{$^H{float}} did not return a defined value at - line 3, at end of line +Constant(1.1): Call to &{$^H{float}} did not return a defined value at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME Binary constant overloading returning undef @@ -100,7 +100,7 @@ use overload; BEGIN { overload::constant binary => sub {} } 0x1 EXPECT -Constant(undef): Call to &{$^H{binary}} did not return a defined value at - line 3, at end of line +Constant(0x1): Call to &{$^H{binary}} did not return a defined value at - line 3, at end of line Execution of - aborted due to compilation errors. ######## # NAME String constant overloading returning undef |