Subject: | overloaded xs magic makes assumption that breaks my stuff |
This package works fine under List::Util::PP,but not under the XS. The
reason is that the XS assumes once a type is magic, it stays magic under
numeric operations. That's definitely not always true.
use List::Util qw(sum);
my $e1 = example->new(7, "test");
sum($e1, 7, 7); # works under ::PP, but not under XS
--
If riding in an airplane is flying, then riding in a boat is swimming.
116 jumps, 48.6 minutes of freefall, 92.9 freefall miles.
Subject: | example.pm |
package example;
use Carp;
use strict;
use warnings;
use overload
'0+' => sub { $_[0][0] },
'""' => sub { my $r = "$_[0][0]"; $r = "+$r" unless $r =~ m/^\-/; $r .= " [$_[0][1]]"; $r },
fallback => 1;
sub new {
my $class = shift;
croak "this package constructor requires precisely two arguments: number, description" unless @_ == 2;
return undef unless defined $_[0];
my $this = bless [@_], $class;
return $this;
}
1;