Front page | perl.datetime |
Postings from July 2003
Re: DT constructor
Thread Next
From:
Joshua Hoblitt
Date:
July 16, 2003 13:03
Subject:
Re: DT constructor
Message ID:
Pine.GSO.4.44.0307160956250.15849-100000@tiu
In a thread long ago we'd had discussed the possibility of breaking up the DT constructor(s) to be a little more friendly to sub-classing. Specifically so the validation behavior could be modified. Here is an example of changes to new() to allow this. What do you think about something like this? It should work for both subclasses and decorators. If these changes were repeated to the other constructors I could write DT::Wrap::Validator as a decorator class.
-J
--
Index: lib/DateTime.pm
===================================================================
RCS file: /cvsroot/perl-date-time/modules/DateTime.pm/lib/DateTime.pm,v
retrieving revision 1.217
diff -u -r1.217 DateTime.pm
--- lib/DateTime.pm 15 Jul 2003 18:58:08 -0000 1.217
+++ lib/DateTime.pm 16 Jul 2003 08:18:45 -0000
@@ -155,7 +155,7 @@
sub new
{
my $class = shift;
- my %p = validate( @_, $NewValidate );
+ my %p = __PACKAGE__->_preprocess_new_params( @_ );
my $last_day = $class->_last_day_of_month( $p{year}, $p{month} );
@@ -218,6 +218,14 @@
}
return $self;
+}
+
+sub _preprocess_new_params
+{
+ my $self = shift;
+ my @p = validate( @_, $NewValidate );
+
+ return @p;
}
sub _calc_utc_rd
Thread Next
-
Re: DT constructor
by Joshua Hoblitt