Skip Menu |

This queue is for tickets about the Date-PeriodParser CPAN distribution.

Report information
The Basics
Id: 24999
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Date-PeriodParser

People
Owner: mcmahon [...] cpan.org
Requestors: michael [...] ndrix.org
Cc:
AdminCc:

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



Subject: Make Lingua::EN::Words2Nums an optional dependency
Lingua::EN::Words2Nums is a dependency but it's only used when parsing phrases like "seven days ago" (ie, phrases with an English description of a number). If a user never uses such phrases, she doesn't really need Lingua::EN::Words2Nums installed. The attached patch makes Lingua::EN::Words2Nums optional by requiring the module at runtime only if parsing demands it.
Subject: optional-words2nums.patch
Auto-merging (0, 2036) /mirror/Date-PeriodParser/branches/optional-words2nums to /mirror/Date-PeriodParser/trunk (base /mirror/Date-PeriodParser/trunk:1921). Patching locally against mirror source svn://tameion/projects. A t/no-words2nums.t U MANIFEST U Makefile.PL U PeriodParser.pm ==== Patch <-> level 1 Source: 5cb99f66-e806-0410-bcd3-b1d9210a1b92:/Date-PeriodParser/branches/optional-words2nums:2035 (svn://tameion/projects) Target: 5cb99f66-e806-0410-bcd3-b1d9210a1b92:/Date-PeriodParser/trunk:1920 (svn://tameion/projects) Log: r2031@ginosko (orig r2030): michael | 2007-02-13 10:37:45 -0700 Create a branch for making the dependency on Lingua::EN::Words2Nums optional. r2032@ginosko (orig r2031): michael | 2007-02-13 11:05:52 -0700 Try to make Lingua::EN::Words2Nums an optional dependency. I still need to write a test for it though. r2034@ginosko (orig r2033): michael | 2007-02-13 12:26:16 -0700 Make Lingua::EN::Words2Nums an optional dependency. r2036@ginosko (orig r2035): michael | 2007-02-16 09:49:21 -0700 Correctly detect whether Devel::Hide is available. === t/no-words2nums.t ================================================================== --- t/no-words2nums.t (revision 1920) +++ t/no-words2nums.t (patch - level 1) @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Test::More; +use Date::PeriodParser; + +eval { + require Devel::Hide; + Devel::Hide->import('Lingua::EN::Words2Nums'); +}; +plan skip_all => 'Devel::Hide not installed' if $@; + +plan tests => 2; + +my ($result, $message) = parse_period('seven days ago'); +cmp_ok( + $result, '<', 0, + 'failure because of missing dependency', +); +is( + $message, + 'Lingua::EN::Words2Nums not installed', + 'dependency missing message', +); === MANIFEST ================================================================== --- MANIFEST (revision 1920) +++ MANIFEST (patch - level 1) @@ -12,6 +12,7 @@ t/07junk.t t/08now.t t/09vague.t +t/no-words2nums.t t/pod.t t/pod-coverage.t META.yml Module meta-data (added by MakeMaker) === Makefile.PL ================================================================== --- Makefile.PL (revision 1920) +++ Makefile.PL (patch - level 1) @@ -5,7 +5,6 @@ 'NAME' => 'Date::PeriodParser', 'VERSION_FROM' => 'PeriodParser.pm', # finds $VERSION 'PREREQ_PM' => { - "Lingua::EN::Words2Nums" => 0, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'PeriodParser.pm', # retrieve abstract from module === PeriodParser.pm ================================================================== --- PeriodParser.pm (revision 1920) +++ PeriodParser.pm (patch - level 1) @@ -1,6 +1,5 @@ package Date::PeriodParser; -use Lingua::EN::Words2Nums; use 5.006; use strict; use warnings; @@ -9,6 +8,7 @@ use constant GIBBERISH => -1; use constant AMBIGUOUS => -2; +use constant DEPENDENCY => -3; # Boring administrative details require Exporter; @@ -94,8 +94,10 @@ my $days = $1; { local $_; - # words2nums() trashes $_. - $days = words2nums($days); + # words2nums() trashes $_. + eval { require Lingua::EN::Words2Nums } + or return (DEPENDENCY, "Lingua::EN::Words2Nums not installed"); + $days = Lingua::EN::Words2Nums::words2nums($days); } if (defined $days) { $days *= -1 if /ago/; @@ -279,7 +281,14 @@ =cut +=head1 DEPENDENCIES +=item * Lingua::EN::Words2Nums + +Any of the phrases that use an English word for a number require that +L<Lingua::EN::Words2Numns> be installed. If those phrases are not used, +the module is optional. + =head1 BUGS Parsing is limited. Some relatively complicated things work fine, but some ==== BEGIN SVK PATCH BLOCK ==== Version: svk v2.0.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Zf zW8t5VQhMmg2KYqzLWjanuN6Qnp9h3m2akqHQvOpnJxq2lXfVkFfMqBUBkGgAstl3AMWShl6tGna nliQ+ufWvzfe/Obeb7XZC+6T2i/mzP96Ztf+eO/Xl76efVL7/vjvnYkMR2gZsszV5ToI09J8iSad 7kF3v9Pdv/NxacyG9Ta5KMDaOtGZzIeQE7O3Wa0CQhZL4nw5LDc++fI0mpA0w1g9zRKydpFrg1xf MfDKwriORr1GiFlZfXtFLt/fHoJU7ELKbvehYWxHGsbk3RWDDON2ckJwfeghkMkQVaJIPZSalLOD y7WbDOIoH1azQfooQhKckgCyc+VltPHg1lL8JG/hArwQsknIbpkLTXOeTSJGqRYTqg2j5DFO1TTG UTlJJxr3HhlvLvVb5RYK/b6QYCtl95s2uNwTQV8Jbns2rgapqvYuhChIhi2etQdRkuajlKylWTSo 7tF1n2B/CIcSYlIQTmmzQXmDWYRR32r6tiAN2qTUIHcyQB/hFASZTMJhNR9jOSr7Ssn7oreQNFnl iHNJRpWcLyHEVhNiPhW+4GeEDrMTotOSw0oHYg3PUl4iWBYCN4EI+3ACoIhRwjzKokpd2X4rbZEu azUdDE/J2kvIWqvJcp87PnPOyO49P8tFWmdJWrEirUOo59uez9l50dKs3HjjEwTWeEEeDQGrlV3e wUqvyWPcMWSAhwgDPdNotXhhcr44Rx1WhyHf/zCJjiHLZXwDzwJ2MZF6iOcyPCPhn+k0UqbdLG6W vaZxudXcXNgF8ptnGi9199Ojh2k5hQgDD3ul0wCXOg1qM9oIQmU1AqY8zqhkgcdb67xYlZzby5Lr bJqMMIR5nD5rFtP1ninOf06xfin1P47hfiA= ==== END SVK PATCH BLOCK ====
On Fri Feb 16 11:58:34 2007, MNDRIX wrote: Show quoted text
> Lingua::EN::Words2Nums is a dependency but it's only used when parsing > phrases like "seven days ago" (ie, phrases with an English description > of a number). If a user never uses such phrases, she doesn't really need > Lingua::EN::Words2Nums installed. > > The attached patch makes Lingua::EN::Words2Nums optional by requiring > the module at runtime only if parsing demands it.
Thanks, applied. Will be in 0.05