We've been using this patch at work for years, and I just forgot to
contribute it back. I hope you find it worth applying.

I believe the typical use case was:

  my $dt = $param || DateTime->now();

In this case $param is used in boolean context, which makes a fallback call
to _stringify(). With the patch, "boolean" just returns true.

The stringification change is a micro-optimization, it is not that
important.



        # optimize boolean and string
        use overload
                '""'  => sub {
                               $_[0]->ymd('-') . 'T' . $_[0]->hms(':')
                             },
                bool  => sub { 1 },

                '<=>' => '_compare_overload',
                'cmp' => '_compare_overload',
                '-'   => '_subtract_overload',
                '+'   => '_add_overload',
                fallback   => 1;

Reply via email to