Bug#552996: libdate-simple-perl: today()/d8()/ymd() broken in subclasses

Chris Share chris at caesium.me.uk
Sat Jan 2 05:42:13 UTC 2010


On Thu, Oct 29, 2009 at 04:18:12PM +0200, Damyan Ivanov wrote:
> Note that constructors of Date::Simple (the base class) work both when 
> called as functions (D::S::today) and when called as a class methods 
> (D::S->today) so perhaps upstream overlooked the problem in the 
> subclasses.
> 
> -- 
> dam

While trying to write a patch to fix this, I found that calling the d8 and ymd constructors as a class method did not work in the base class or any of the subclasses, producing message such as:
$ perl -MDate::Simple -e 'print Date::Simple->d8('20100102');'
Usage: Date::Simple::_d8(obj_or_class, d8) at /usr/lib/perl5/Date/Simple.pm line 70.

This seems to be caused by "return $_[0]->SUPER::_d8(@_);" which ends up with _d8 being called with two copies of the class name or object. This bug is fixed by replacing the above with "return shift->SUPER::_d8(@_);" and the corresponding change for _ymd.

I attach a patch which makes the above changes and copies the constructors from the base class into the three subclasses (D8, Fmt and ISO) which appears to fix both bugs.

Test script:
echo "Base:"
perl -MDate::Simple -e 'print Date::Simple::today()."\n";'
perl -MDate::Simple -e 'print Date::Simple->today()."\n";'
perl -MDate::Simple -e 'print Date::Simple::ymd(2010,01,02)."\n";'
perl -MDate::Simple -e 'print Date::Simple->ymd(2010,01,02)."\n";'
perl -MDate::Simple -e 'print Date::Simple::d8('20100102')."\n";'
perl -MDate::Simple -e 'print Date::Simple->d8('20100102')."\n";'
echo "Fmt:"
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt::today()."\n";'
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt->today()."\n";'
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt::ymd(2010,01,02)."\n";'
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt->ymd(2010,01,02)."\n";'
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt::d8('20100102')."\n";'
perl -MDate::Simple::Fmt -e 'print Date::Simple::Fmt->d8('20100102')."\n";'
echo "D8:"
perl -MDate::Simple::D8 -e 'print Date::Simple::D8::today()."\n";'
perl -MDate::Simple::D8 -e 'print Date::Simple::D8->today()."\n";'
perl -MDate::Simple::D8 -e 'print Date::Simple::D8::ymd(2010,01,02)."\n";'
perl -MDate::Simple::D8 -e 'print Date::Simple::D8->ymd(2010,01,02)."\n";'
perl -MDate::Simple::D8 -e 'print Date::Simple::D8::d8('20100102')."\n";'
perl -MDate::Simple::D8 -e 'print Date::Simple::D8->d8('20100102')."\n";'
echo "ISO:"
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO::today()."\n";'
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO->today()."\n";'
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO::ymd(2010,01,02)."\n";'
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO->ymd(2010,01,02)."\n";'
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO::d8('20100102')."\n";'
perl -MDate::Simple::ISO -e 'print Date::Simple::ISO->d8('20100102')."\n";'

The output using version 3.03.03 is:
Base:
2010-01-02
2010-01-02
2010-01-02
Usage: Date::Simple::_ymd(obj_or_class, y, m, d) at /usr/lib/perl5/Date/Simple.pm line 97.
2010-01-02
Usage: Date::Simple::_d8(obj_or_class, d8) at /usr/lib/perl5/Date/Simple.pm line 70.
Fmt:
Can't call method "_today" on an undefined value at /usr/lib/perl5/Date/Simple/Fmt.pm line 11.
2010-01-02
Can't call method "_ymd" without a package or object reference at /usr/lib/perl5/Date/Simple/Fmt.pm line 12.
2010-01-02
Can't call method "_d8" without a package or object reference at /usr/lib/perl5/Date/Simple/Fmt.pm line 10.
2010-01-02
D8:
Can't call method "_today" on an undefined value at /usr/lib/perl5/Date/Simple/D8.pm line 11.
20100102
Can't call method "_ymd" without a package or object reference at /usr/lib/perl5/Date/Simple/D8.pm line 12.
20100102
Can't call method "_d8" without a package or object reference at /usr/lib/perl5/Date/Simple/D8.pm line 10.
20100102
ISO:
Can't call method "_today" on an undefined value at /usr/lib/perl5/Date/Simple/ISO.pm line 11.
2010-01-02
Can't call method "_ymd" without a package or object reference at /usr/lib/perl5/Date/Simple/ISO.pm line 12.
2010-01-02
Can't call method "_d8" without a package or object reference at /usr/lib/perl5/Date/Simple/ISO.pm line 10.
2010-01-02

The output with the patched version is:
Base:
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02
Fmt:
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02
D8:
20100102
20100102
20100102
20100102
20100102
20100102
ISO:
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02
2010-01-02

Thanks,
Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libdate-simple-perl-constructor-fix.diff
Type: text/x-diff
Size: 4791 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/attachments/20100102/3c257f70/attachment.diff>


More information about the pkg-perl-maintainers mailing list