dmitri has asked for the wisdom of the Perl Monks concerning the following question:
Note that this subroutine may return undef. Now, SOAP::Serializer calls subroutine gen_id on references, which for normal objects is just the value of memory address:use overload ("0+" => 'value'); sub value { my $self = shift; exists $self->{'-value'} ? $self->{'-value'} : undef; }
Now, the problem is that when objects of type Error do not have a value (returns undef), this produces a segfault in perl 5.6.1. This problem can be demonstrated with the following short script:sub gen_id { sprintf "%U", $_[1] }
We see that when numeric conversion overloading function returns undef to built-in Perl functions that invoke it, that crashes perl. My question is, how do I approach this problem? Do I try topackage My; use overload ('0+' => 'num_conv'); sub new { my $self = shift; bless {}, ref($self) || $self; } sub num_conv { undef } package main; my $var = My->new; print int($var);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: When numeric conversion overloading goes awry.
by dragonchild (Archbishop) on Jan 24, 2006 at 19:34 UTC | |
by dmitri (Priest) on Jan 25, 2006 at 16:25 UTC | |
by dragonchild (Archbishop) on Jan 25, 2006 at 18:14 UTC | |
|
Re: When numeric conversion overloading goes awry.
by chromatic (Archbishop) on Jan 24, 2006 at 23:03 UTC | |
by dmitri (Priest) on Jan 25, 2006 at 13:52 UTC | |
|
Re: When numeric conversion overloading goes awry.
by Anonymous Monk on Jan 24, 2006 at 19:48 UTC |