The cause of the problem is that the tests try to do a string comparison
of the "unit_base" objects to verify the result. But with the string
comparison, overload will not fallback on using the object's string
overload, as described in the documentation
https://metacpan.org/module/overload#Magic-Autogeneration).
This solution explicitly stringifies the objects before doing the string
comparison tests.
Index: overload.t
===================================================================
--- overload.t (revision 2697)
+++ overload.t (working copy)
@@ -8,13 +8,13 @@
use Date::Piece qw(date centuries years months weeks days);
my $w7 = 7*weeks;
-is($w7, '7weeks');
+is("$w7", '7weeks');
my $aw7 = $w7;
$aw7++;
-is($aw7, '8weeks');
+is("$aw7", '8weeks');
$aw7*=2;
-is($aw7, '16weeks');
-is($w7, '7weeks');
+is("$aw7", '16weeks');
+is("$w7", '7weeks');
{
my $fails = eval{$aw7/3};
my $err = $@;
@@ -27,15 +27,15 @@
}
my $m7 = 7*months;
-is($m7, '7months');
+is("$m7", '7months');
my $am7 = $m7;
$am7++;
-is($am7, '8months');
+is("$am7", '8months');
$am7*=2;
-is($am7, '16months');
+is("$am7", '16months');
$am7/=2;
-is($am7, '8months');
-is($m7, '7months', 'untouched');
+is("$am7", '8months');
+is("$m7", '7months', 'untouched');
{
my $fails = eval{$am7/3};
my $err = $@;
@@ -43,20 +43,20 @@
}
my $y7 = 7*years;
-is($y7, '7years');
+is("$y7", '7years');
my $ay7 = $y7;
$ay7++;
-is($ay7, '8years');
+is("$ay7", '8years');
$ay7*=2;
-is($ay7, '16years');
+is("$ay7", '16years');
$ay7/=2;
-is($ay7, '8years');
-is($y7, '7years', 'untouched');
+is("$ay7", '8years');
+is("$y7", '7years', 'untouched');
{
eval{$ay7/=3};
my $err = $@;
like($err, qr/can only work in integer years/);
- is($ay7, '8years');
+ is("$ay7", '8years');
}
{
my $failed = eval{4.3*days};