Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime-TimeZone CPAN distribution.

Report information
The Basics
Id: 44724
Status: resolved
Priority: 0/
Queue: DateTime-TimeZone

People
Owner: Nobody in particular
Requestors: dolmen [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.86
Fixed in: 0.87



Subject: [PATCH] can't override TZ detection in ::Local (_load_subclass is broken)
My $^O is 'hpux'. I wrote my own DateTime::TimeZone::Local::hpux to workaround RT#44721 but it is not loaded. Instead DateTime::TimeZone::Local::Unix is used. The problem is that in DateTime::TimeZone::Local _load_subclass always load DateTime::TimeZone::Local::Unix if $^O is not in in %subclass. This makes adding a $^O specific subclass impossible, which was the point of this code. The broken line is: my $os_name = shift || $subclass{ $^O } || 'Unix'; It should be: my $os_name = shift || $subclass{ $^O } || $^O; Defaulting to 'Unix' is handled in the following lines. Current code (0.86): -------8<-------8<-------8<-------8<-------8<-------8<------- sub _load_subclass { my $class = shift; my $os_name = shift || $subclass{ $^O } || 'Unix'; my $subclass = $class . '::' . $os_name; return $subclass if $subclass->can('Methods'); eval "use $subclass"; if ( my $e = $@ ) { if ( $e =~ /locate.+$os_name/ ) { $subclass = $class . '::' . 'Unix'; eval "use $subclass"; die $@ if $@; } else { die $e; } } return $subclass; } -------8<-------8<-------8<-------8<-------8<-------8<-------
Subject: [PATCH+TEST] can't override TZ detection in ::Local (_load_subclass is broken)
I've attached a test (20local-subclass.t) and verified that my proposed fix above pass it.
#!perl =head1 SYNOPSIS Test for RT#44724. See L<https://rt.cpan.org/Ticket/Display.html?id=44724> =head1 AUTHOR Olivier MenguE<eacute> C<<< dolmen@cpan.org >>> =head1 LICENSE Same as L<DateTime::TimeZone>. =cut package DateTime::TimeZone::Local::os42; use strict; use warnings; use DateTime::TimeZone::OffsetOnly; sub Methods { ( 'FromHardCoded' ) } sub FromHardCoded { DateTime::TimeZone::OffsetOnly->new( offset => 42*60 ) } 1; package main; use strict; use warnings; use Test::More tests => 4; use DateTime::TimeZone::OffsetOnly; my $tz_name = '+2520'; my $tz1 = DateTime::TimeZone::OffsetOnly->new( offset => 42*60 ); isa_ok($tz1, 'DateTime::TimeZone'); is($tz1->name, $tz_name); # Set our virtual OS that has his own method for determining local TZ $^O = 'os42'; my $tz2 = DateTime::TimeZone->new(name => 'local'); isa_ok($tz2, 'DateTime::TimeZone'); is($tz1->name, $tz_name);