Ok just to sanity check overload doesnt seem to be working for me. I don't know if it's the version of perl I have, or the version of overload.pm, or something wrong with how I've implemented it, but this code doesnt work for me.
perl version
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
overload version
perl -Moverload -e 'print "$overload::VERSION\n";'
1.07
Token.pm
package Token;
use namespace::autoclean;
use Data::Dumper;
use Moose;
use Moose::Util::TypeConstraints;
use overload '+' => \&_overload_add, fallback => 1;
has 'secretvalue' => ( is => 'rw', isa => 'Int');
sub _overload_add{
my ( $one, $two ) = @_;
my $value = $one->secretvalue() + $two->secretvalue();
return ($value);
}
main
use strict;
use warnings;
use Token;
my $t = Token->new( secretvalue => 17, key => 'x' );
my $t2 = Token->new( secretvalue => 12, key => 'y' );
my $x = $t + $t2;
print $x;
prints
$VAR1 = 12900840;
The worst part is that I'm not getting any kind of warning or errors in the log.
UPDATE
Thanks to Freido for finding the problem. I've updated the question just in case anyone else stumbles on this.
Does the Perl/Moose community generally not use overload?