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;