On Wednesday 15 October 2003 01:02 pm, Mark Stosberg wrote:
> > I'm going to be creating a set of wrapper classes that presents a common
> > interface to some of the CPAN modules that supports the above datatypes
> > and just does the "Right Thing???".
>
> Could you say more about what the "Right Thing" is, or give an example?
> That might help the discussion of the appropriate name.

Here is how some objects may be constructed:

   my $date1 = new DataType("Wed, 04 Jun 2003 03:50:23 PDT");
   my $date2 = new DataType::Date("Yesterday");
   my $ipaddr = new DataType("192.168.121.155");
   my ($date, $time, $domain) = new DataType(
       date => '2003/04/15',
       time => '12:45pm',
       dns  => 'perl.org');

   my $interval = new DataType::Interval("2 weeks");
   my $date3 = $date2 + $interval;
   # -- or --
   my $date3 = new DataType::Date("Oct 29, 2003");
   $date3->add($interval);

   print $date3;  # prints "2003-11-12"
   # -- or --
   print $date3->toString;

Their "" overloaded operator would simply invoke the object's toString method, 
which would print out whatever the internal value is in the "right way".

These classes would mainly be wrappers for other classes on CPAN (like 
DateTime and/or Date::Manip, et al) but this would provide a common API to 
the classes, so you can just call $obj->toString and get a result.

My idea is that, with Class::DBI (as well as other object factories out 
there), you don't always know what data type you're going to be dealing with, 
and though Perl's regular expression support is great, you don't want to have 
to validate every possible permutation of a datatype by hand.  I have had a 
lot of bugs in my Intranet application mainly because when pulling a value 
out of a database as a string, rather than an object, whitespaces or timezone 
offsets, etc, can cause my program to give off pretty funky results.  By 
having all (or almost all) values returned from Class::DBI be objects, I can 
munge the data simply by making method calls.

-- 
/* Michael A. Nachbaur <[EMAIL PROTECTED]>
 * http://nachbaur.com/pgpkey.asc
 */

"Out," he said. People who can supply that amount of firepower don't need to 
supply verbs as well.

Reply via email to