* Iain 'Spoon' Truskett ([EMAIL PROTECTED]) [12 Mar 2003 17:08]:
> * Dave Rolsky ([EMAIL PROTECTED]) [12 Mar 2003 17:04]:

> [...]
> > There's nothing wrong with this, but if one method returns $self,
> > then I'd say _all_ set methods should return it, so method chaining
> > is possible, like:

> I was hoping you'd say that.

> I'll try to get a thorough patch done in the next day or so.

See attached (should one patch and one test file).

I'm not exceptionally pleased with the revised doco.


cheers,
-- 
Iain.
? diffs
? t/17returnobj.t
Index: lib/DateTime.pm
===================================================================
RCS file: /cvsroot/perl-date-time/modules/DateTime.pm/lib/DateTime.pm,v
retrieving revision 1.107
diff -U5 -r1.107 DateTime.pm
--- lib/DateTime.pm     11 Mar 2003 03:33:25 -0000      1.107
+++ lib/DateTime.pm     12 Mar 2003 12:19:31 -0000
@@ -639,10 +639,12 @@
             $self->{utc_rd_days} = $self->_ymd2rd( $y, $m + $deltas{months}, $d );
         }
     }
 
     $self->_calc_local_rd;
+
+    return $self;
 }
 
 use constant INFINITY     =>       100 ** 100 ** 100 ;
 use constant NEG_INFINITY => -1 * (100 ** 100 ** 100);
 
@@ -690,10 +692,12 @@
         );
 
     my $new_dt = (ref $self)->new( %old_p, %p );
 
     %$self = %$new_dt;
+
+    return $self;
 }
 
 sub truncate {
     my $self = shift;
     my %p = validate( @_,
@@ -714,10 +718,12 @@
     }
 
     my $new_dt = (ref $self)->new(%new);
 
     %$self = %$new_dt;
+
+    return $self;
 }
 
 sub set_time_zone {
     my ( $self, $tz ) = @_;
 
@@ -731,10 +737,12 @@
     }
     elsif ( ! $was_floating )
     {
         $self->_calc_local_rd;
     }
+
+    return $self;
 }
 
 
 1;
 
@@ -1182,11 +1190,19 @@
 that different operating systems have different epoch beginnings is
 another source of bugs.
 
 =back
 
-Other methods provided by C<DateTime.pm> are:
+The remaining methods provided by C<DateTime.pm>, except where otherwise
+specified, return the object itself, thus making method chaining
+possible. For example:
+
+  my $dt = DateTime->now->set_time_zone( 'Australia/Sydney' );
+
+  my $first = DateTime
+               ->last_day_of_month( year => 2003, month => 3 )
+               ->add( days => 1 );
 
 =over 4
 
 =item * set( .. )
 

Reply via email to