It didn't work. So, I went backwards and tried in standard Perl. That worked fine, and so did Moose when I tried that.
Can anyone see anything wrong with the following test case (only the last test fails)?
(Perl 5.10.1 and MooseX::Declare 0.33)
package InPerl; use strict; use warnings; use overload '""' => \&to_string; sub new { bless { val=>$_[1] }, $_[0] } sub to_string { sprintf "(%s)", $_[0]->{val} } package InMoose; use Moose; use overload '""' => \&to_string; has val => is => 'rw'; sub to_string { sprintf "(%s)", $_[0]->val } use MooseX::Declare; class InDeclare { use overload '""' => \&to_string2; has val => is => 'rw'; sub to_string2 { sprintf "(%s)", $_[0]->val } }; package main; use strict; use warnings; use Test::More; my $p = InPerl->new(44); is $p, "(44)", "perl is ok"; is "$p", "(44)", "perl is ok (Q)"; my $m = InMoose->new(val=>66); is $m, "(66)", "moose is ok"; is "$m", "(66)", "moose is ok (Q)"; my $d = InDeclare->new(val=>666); is $d, "(666)", "mxd is ok)"; # PASS: "(666)" is "$d", "(666)", "mxd is ok (Q)"; # FAIL: "InDeclare=HASH(0x2166ab0)" done_testing;
and the output:
ok 1 - perl is ok ok 2 - perl is ok (Q) ok 3 - moose is ok ok 4 - moose is ok (Q) ok 5 - mxd is ok) not ok 6 - mxd is ok (Q) # Failed test 'mxd is ok (Q)' # at /home/bri/git/W/oops/foo line 55. # got: 'InDeclare=HASH(0x20a1960)' # expected: '(666)' 1..6 # Looks like you failed 1 test of 6.
In reply to MooseX::Declare and overload by FunkyMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |