On Fri, 19 Dec 2003, Marco Marongiu wrote: > As I said in my first mail, Date::Iterator came out to solve a problem I > had at work. And as it happened to you, I decide to write a new module > after a lot of searching into cpan. DateTime modules didn't come out > from those searches, unfortunately. But, as Dave Rolsky recognized, even > if I found them the documentation itself doesn't encourage people to use > it for simple tasks... > > Could I contribute to the DateTime project? I think I can't. Working > with calendars and times would require me an effort bigger than I can > take. If you look at the module code, it am just plain using a single > function from a single module (Date::Calc): I have no experience on > doing things like that myself.
> Proliferation of modules on CPAN is evil? Maybe. Maybe not. It could > create confusion, you are right. But... well, I'll say in italian: "Cio` > che hai in piu` non ti impoverisce"; I don't have a good translation in > english, but it could sound like "things you got and don't need don't > make you poor". It's a natural selection process: people search for > modules that do the job, read the docs and make a choice. If my module > is bad, they simply won't use it. > > Instead of hiding my module in my insignificant website, wouldn't it be > better to write on top and bottom of the docs an advice like "this is a > small module and does a few things; you probabily want to take a look at > DateTime and DateTime::Event::Recurrence <http://datetime.perl.org>"? OK, that will teach me not to get suckered ino this kind of discussion ;--( I think your module could be rewritten as syntaxic sugar over the existing DateTime::* ones (or merged as a patch into an existing one). It brings 2 things: a compact way to create a date for a day, and a compact syntax to create an ierator over days. What integrating it into the DateTime hierarchy would do is to allow it to play nice with the other modules. I haven't kept all the mails in the thread so I can't look at your original code, but I believe the following would work in a similar way. I would move the simpledate2datetime method somewhere else though, as it is somewhat orthogonal (do I get points for using this first in this thread?) to the iteration feature. Does this make sense? #!/usr/bin/perl -w use strict; # use as a list my @days = DateTime::Iterator->new( from => "2001-11-03", to => "2001-11-10"); foreach my $day (@days ) { print $day->ymd . "\n"; } # use as an iterator my $days= DateTime::Iterator->new( from => [ 2001, 11, 03], to => [ 2001, 11, 10]); while( my $day= $days->next) { print $day->ymd . "\n"; } package DateTime::Iterator; use Carp; use DateTime; use DateTime::Event::Recurrence; sub new { my( $class, %options)= @_; carp "need a to and from option to daily_sequence" unless( defined( $options{from}) && defined( $options{to})); my $from = simpledate2datetime( $options{from}); my $to = simpledate2datetime( $options{to}); my $daily_set = DateTime::Event::Recurrence->daily; return wantarray ? $daily_set->as_list( start => $from, end => $to ) : $daily_set->iterator( start => $from, end => $to ) ; } sub simpledate2datetime { my $simpledate= shift; unless( UNIVERSAL::isa( $simpledate, 'ARRAY')) { $simpledate= [split /-/, $simpledate ] } my %date_args; @date_args{qw( year month day)}= @$simpledate; return DateTime->new( %date_args); } -- Michel Rodriguez Perl & XML http://www.xmltwig.com