From 3de4de70eb8049b17b913952439359ec6fde4d1d Mon Sep 17 00:00:00 2001
From: Slaven Rezic <
[email protected]>
Date: Sat, 26 Dec 2015 20:08:27 +0100
Subject: [PATCH] compatibility with newer DateTime::Locale versions (RT
#108601)
---
lib/DateTime/Format/Human/Duration.pm | 6 +++++-
lib/DateTime/Format/Human/Duration/Locale.pm | 25 +++++++++++++++++--------
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/lib/DateTime/Format/Human/Duration.pm b/lib/DateTime/Format/Human/Duration.pm
index 53af6e1..749d40c 100644
--- a/lib/DateTime/Format/Human/Duration.pm
+++ b/lib/DateTime/Format/Human/Duration.pm
@@ -17,7 +17,11 @@ sub format_duration_between {
my $dur = $dt - $dtb;
if (!exists $args{'locale'}) {
- $args{'locale'} = $dt->{'locale'}{'id'};
+ if (UNIVERSAL::can($dt->{'locale'}, 'code')) {
+ $args{'locale'} = $dt->{'locale'}->code; # DateTime::Locale v1
+ } else {
+ $args{'locale'} = $dt->{'locale'}->id; # DateTime::Locale v0
+ }
}
return $span->format_duration($dur, %args);
diff --git a/lib/DateTime/Format/Human/Duration/Locale.pm b/lib/DateTime/Format/Human/Duration/Locale.pm
index c71a728..58670c0 100644
--- a/lib/DateTime/Format/Human/Duration/Locale.pm
+++ b/lib/DateTime/Format/Human/Duration/Locale.pm
@@ -46,15 +46,24 @@ sub determine_locale_from {
return '' if !$args_hr->{'get_locale_from'};
if (ref $args_hr->{'get_locale_from'}) {
- my $ns = ref($args_hr->{'get_locale_from'});
+ my $locale_obj;
+ if (UNIVERSAL::can($args_hr->{'get_locale_from'}, 'locale')) {
+ $locale_obj = $args_hr->{'get_locale_from'}->locale;
+ }
+ else {
+ $locale_obj = $args_hr->{'get_locale_from'};
+ }
- if (exists $args_hr->{'get_locale_from'}{'locale'}) {
- $ns = exists $args_hr->{'get_locale_from'}{'locale'}{'id'} ? $args_hr->{'get_locale_from'}{'locale'}{'id'} : ref($args_hr->{'get_locale_from'}{'locale'});
- }
- elsif ($ns =~ m{^DateTime::Locale::} && exists $args_hr->{'get_locale_from'}{'id'}) {
- $ns = $args_hr->{'get_locale_from'}{'id'};
- }
- ($args_hr->{'get_locale_from'}) = reverse split /::/, $ns;
+ if (UNIVERSAL::can($locale_obj, 'code')) {
+ $args_hr->{'get_locale_from'} = $locale_obj->code; # DateTime::Locale v1
+ }
+ elsif (UNIVERSAL::can($locale_obj, 'id')) {
+ $args_hr->{'get_locale_from'} = $locale_obj->id; # DateTime::Locale v0
+ }
+ else {
+ my $ns = ref($args_hr->{'get_locale_from'});
+ ($args_hr->{'get_locale_from'}) = reverse split /::/, $ns;
+ }
}
my ($short) = split(/[-_]+/,$args_hr->{'get_locale_from'});
--
2.1.2