I think you are meaning something like this (untested): sub sunrise_sunset { my $class = shift; my $dt = shift; my $self = $class->_new( @_ ); return DateTime::Set->from_datetimes( dates => $self->_current_rise_set->( $dt ) ); }
I believe a DateTime::Span would be a more useful return value, in this case. - Flavio S. Glock Hill, Ronald wrote: > > Hi Flavio, > > I'm stuck :( > > I am trying to implement the changes that were discussed > recently on the list and am running into problems. > > Here is what I have tried: > I have renamed the currect sunrise_sunset to > _sunrise_sunset (easy) > > then I wrote a new sunrise_sunset sub to accommodate > the change request. Here is what I have: > > sub sunrise_sunset { > my $class = shift; > my $self = $class->_new( @_ ); > return DateTime::Set->from_datetimes( > dates => sub { > $self->_current_rise_set->($_[0]); > } > ); > } > > Then I wrote another sub ( _current_rise_set) > That has the following > > sub _current_rise_set { > my $self = shift; > my $dt = shift; > croak( "Dates need to be DateTime objects (" . ref($dt) . ")" ) > unless ( $dt->isa('DateTime') ); > my ( $tmp_rise, $tmp_set ) = _sunrise( $self, $dt ); > return [$tmp_rise, $tmp_set] ; > > } > > The idea is that I want to keep the current overall structure > of the module. In order to do this I though that all I needed to do was > to have the module return (as a set) the date of rise/set. > So the users of the module would do something like this: > > #!/usr/bin/perl > use strict; > use warnings; > use DateTime; > use DateTime::Event::Sunrise: > > my $dt = DateTime->new( year => 2003, > month => 12, > day => 01, > time_zone => 'America/Los_Angeles', > ); > > my $sun_set = DateTime::Event::Sunrise ->sunrise_sunset( > longitude =>'-118' , > latitude => '33', > ); > > then to generate the DateTime Set do this > > my $dt_set = $sun_set->($dt); > > Well, needless to say this does not work :( > The reason is because the from_datetimes method does not > accept a coderef (only an arrayref) Even if it did > I still don't think it would work. > > Is there a reason it only accepts a arrayref? > ( it would be kinda cool if it did accept a coderef). > > Anyway, if there is any insite you can provide it would be most > helpful. > > Thanks > > Ron Hill