Skip Menu |

This queue is for tickets about the DateTime-Format-Duration-ISO8601 CPAN distribution.

Report information
The Basics
Id: 124293
Status: resolved
Priority: 0/
Queue: DateTime-Format-Duration-ISO8601

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

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: DateTime::Format::Duration::ISO8601 doesn't "require DateTime::Duration;"
Hi!

I'm using DateTime::Format::Duration::ISO8601 directly to parse a string in order to check it's validity.

DateTime::Format::Duration::ISO8601->parse_duration is supposed to return a DateTime::Duration object, but if that module isn't loaded, parse_duration will throw an «Can't locate object method "new" via package "DateTime::Duration" (perhaps you forgot to load "DateTime::Duration"?)» error.

Possible solutions:

1) Update docs example to show that DateTime::Duration also has to be loaded ("require DateTime::Duration;")

2) Add a line with «require DateTime::Duration» somewhere in DT::F::D::ISO8601 where it's appropriate.

3) Don't create a DateTime::Duration object in parse_duration

I'd like to recommend 2)  (-:


Also, would you mind adding an is_valid_iso8601_duration method to your module too? (one that just returns false/true values, and doesn't bother loading/creating a DateTime::Duration object).

Thanks,

- Salve
On Thu, 1 Feb 2018 20:33:25 GMT, sjn wrote: Show quoted text
> Hi! > > I'm using DateTime::Format::Duration::ISO8601 directly to parse a > string in > order to check it's validity. > > DateTime::Format::Duration::ISO8601->parse_duration is supposed to > return a > DateTime::Duration object, but if that module isn't loaded, > parse_duration will > throw an «Can't locate object method "new" via package > "DateTime::Duration" > (perhaps you forgot to load "DateTime::Duration"?)» error. > > Possible solutions: > > 1) Update docs example to show that DateTime::Duration also has to be > loaded > ("require DateTime::Duration;") > > 2) Add a line with «require DateTime::Duration» somewhere in > DT::F::D::ISO8601 > where it's appropriate. > > 3) Don't create a DateTime::Duration object in parse_duration > > I'd like to recommend 2) (-: > > > Also, would you mind adding an is_valid_iso8601_duration method to > your module > too? (one that just returns false/true values, and doesn't bother > loading/creating a DateTime::Duration object). > > Thanks, > > - Salve
I've added "require DateTime::Duration", thanks for the report. As for the second request, you can use the already existing (but previously undocumented) parse_duration_as_deltas() method, which will parse a duration string into hashref without creating a DateTime::Duration object. I'll be releasing a new version shortly.