Re: Bug: DT::Event::Recurrence Modifies Params
I noticed a little bug today. DateTime::Event::Recurrence modifies the parameters that are passed to it. I suspect these lines.. Index: lib/DateTime/Event/Recurrence.pm === RCS file: /cvsroot/perl-date-time/modules/DateTime-Event-Recurrence/lib/DateTime/Event/Recurrence.pm,v retrieving revision 1.85 diff -d -u -r1.85 Recurrence.pm --- lib/DateTime/Event/Recurrence.pm22 Sep 2004 16:19:23 - 1.85 +++ lib/DateTime/Event/Recurrence.pm7 Jan 2005 09:58:58 - @@ -684,11 +684,11 @@ if ( $unit eq 'days' ) { # map rfc2445 weekdays to numbers -@{$args{$unit}} = map { +$args{$unit} = [ map { $_ =~ /[a-z]/ ? $_ = $weekdays{$_} : $_ -} @{$args{$unit}}; +} @{$args{$unit}} ]; } @{$args{$unit}} = sort { $a <=> $b } @{$args{$unit}}; # put positive values first However, I don't think this solves the whole problem. It looks like there are a lot of @{ $args { $foo } } = @blah_blah; type of constructs, and that's where this is all coming from. If no one objects, I don't mind doing a sweep change and remove all such occurences. It's a three day weekend over in this corner of Asia. --d
Re: [Perl-date-time-dev] Lots a changes.
On Fri, 7 Jan 2005, Daisuke Maki wrote: +sub _get_cache +{ +if (! defined $CACHE) { +require Cache::FileCache; + +my $namespace = __PACKAGE__; +$namespace =~ s/::/-/g; +$CACHE = Cache::FileCache->new( { +namespace => $namespace, +default_expires_in => $Cache::Cache::EXPIRES_NEVER +}); +} +return $CACHE; +} This should probably default to MemoryCache, for politeness. Also, how about making it a method instead of a global? -dave /*=== VegGuide.Org Your guide to all that's veg. ===*/
Re: Bug: DT::Event::Recurrence Modifies Params
On Fri, 7 Jan 2005, Daisuke Maki wrote: I suspect these lines.. Index: lib/DateTime/Event/Recurrence.pm === RCS file: /cvsroot/perl-date-time/modules/DateTime-Event-Recurrence/lib/DateTime/Event/Recurrence.pm,v retrieving revision 1.85 diff -d -u -r1.85 Recurrence.pm --- lib/DateTime/Event/Recurrence.pm22 Sep 2004 16:19:23 - 1.85 +++ lib/DateTime/Event/Recurrence.pm7 Jan 2005 09:58:58 - @@ -684,11 +684,11 @@ if ( $unit eq 'days' ) { # map rfc2445 weekdays to numbers -@{$args{$unit}} = map { +$args{$unit} = [ map { $_ =~ /[a-z]/ ? $_ = $weekdays{$_} : $_ -} @{$args{$unit}}; +} @{$args{$unit}} ]; } @{$args{$unit}} = sort { $a <=> $b } @{$args{$unit}}; # put positive values first However, I don't think this solves the whole problem. It looks like there are a lot of @{ $args { $foo } } = @blah_blah; type of constructs, and that's where this is all coming from. If no one objects, I don't mind doing a sweep change and remove all such occurences. It's a three day weekend over in this corner of Asia. That seems like a good idea. Messing with your callers' arguments is generally bad form. -dave /*=== VegGuide.Org Your guide to all that's veg. ===*/
Need help from Windows folks for Time::Local
Could people with Windows run the following bit of Perl: perl -le '@t = gmtime(-1); print grep {defined} @t ? "[EMAIL PROTECTED]" : "undef\n"' And tell me what it prints. Someone reported a bug in Time::Local on WinXP saying that it produced lots of warnings given a value before the start of the epoch, but I thought time_t on Windows was signed, so that should work. -dave /*=== VegGuide.Org Your guide to all that's veg. ===*/
Re: Need help from Windows folks for Time::Local
Dave Rolsky wrote: Could people with Windows run the following bit of Perl: perl -le '@t = gmtime(-1); print grep {defined} @t ? "[EMAIL PROTECTED]" : "undef\n"' OK. c:\>perl -le '@t = gmtime(-1); print grep {defined} @t ? "[EMAIL PROTECTED]" : "undef\n"' Can't find string terminator "'" anywhere before EOF at -e line 1. ;) Sorry, I know that's not what you wanted to know: c:\>perl -le "@t = gmtime(-1); print grep {defined} @t ? \"[EMAIL PROTECTED]" : \"undef\n\"" undef HTH John -- John Peacock Director of Information Research and Technology Rowman & Littlefield Publishing Group 4501 Forbes Boulevard Suite H Lanham, MD 20706 301-459-3366 x.5010 fax 301-429-5748
Re: [Perl-date-time-dev] Lots a changes.
Hmm, my idea was that once calculated, the values never need to be recalculated ever again. In that sense, nth_new_moon() could have just been a table instead of a something that computes these values. That's why the (possibly) system-wide cache. This should probably default to MemoryCache, for politeness. Also, how about making it a method instead of a global? when you say "make it a method", do you mean to make the cache an instance variable, or are you talking about just how it gets called? I suppose it can be an instance variable too, it just that the savings for using a cache is not going to be that big. --d
Re: Bug: DT::Event::Recurrence Modifies Params
can Flavio/Dave/somebody review this code? I basically opted to copy over $args{$unit} to a different array before doing any processing, and refactored one bit of code. All existing tests passed. --d Index: lib/DateTime/Event/Recurrence.pm === RCS file: /cvsroot/perl-date-time/modules/DateTime-Event-Recurrence/lib/DateTime/Event/Recurrence.pm,v retrieving revision 1.85 diff -d -u -r1.85 Recurrence.pm --- lib/DateTime/Event/Recurrence.pm22 Sep 2004 16:19:23 - 1.85 +++ lib/DateTime/Event/Recurrence.pm8 Jan 2005 00:54:16 - @@ -619,6 +619,15 @@ return $set; } +sub _sort_positive_first +{ +my @sorted = sort { $a <=> $b } @_; +# put positive values first +my @ret = grep { $_ >= 0 } @sorted; +push @ret, $_ for grep { $_ < 0 } @sorted; + +return @ret; +} # method( hours => 10 ) # method( hours => 10, minutes => 30 ) @@ -676,8 +685,13 @@ next unless exists $args{$unit}; -$args{$unit} = [ $args{$unit} ] -unless ref( $args{$unit} ) eq 'ARRAY'; +# copy the argument values before proceeding, so that we +# don't accidentally modify it. +if (ref($args{$unit}) eq 'ARRAY') { +$args{$unit} = [ @{$args{$unit}} ]; +} else { +$args{$unit} = [ $args{$unit} ]; +} # TODO: sort _after_ normalization @@ -690,13 +704,7 @@ $_ } @{$args{$unit}}; } -@{$args{$unit}} = sort { $a <=> $b } @{$args{$unit}}; -# put positive values first -# warn "Arguments: $unit = @{$args{$unit}}"; -my @tmp = grep { $_ >= 0 } @{$args{$unit}}; -push @tmp, $_ for grep { $_ < 0 } @{$args{$unit}}; -# print STDERR "$unit => @tmp\n"; -@{$args{$unit}} = @tmp; +$args{$unit} = [ _sort_positive_first(@{$args{$unit}}) ]; $ical_string .= uc( ';' . $ical_name{$unit} . '=' . join(",", @{$args{$unit}} ) ) unless $unit eq 'nanoseconds'; @@ -755,14 +763,7 @@ } # redo argument sort - -@{$args{$unit}} = sort { $a <=> $b } @{$args{$unit}}; -# put positive values first -my @tmp = grep { $_ >= 0 } @{$args{$unit}}; -push @tmp, $_ for grep { $_ < 0 } @{$args{$unit}}; -# print STDERR "$unit => @tmp\n"; -@{$args{$unit}} = @tmp; - +$args{$unit} = [ _sort_positive_first(@{$args{$unit}}) ]; } else { # year day
Re: [Perl-date-time-dev] Lots a changes.
when you say "make it a method", do you mean to make the cache an instance variable, or are you talking about just how it gets called? bleh. instance variables? what am I saying. There are only functional interface to this module... I'm guessing this is kind of what you are talking about: DateTime::Util::Astro::Moon::set_cache($cache); my $cache = DateTime::Util::Astro::Moon::get_cache(); --d