On Thu, Jan 16, 2003 at 12:05:38PM -0600, Dave Rolsky wrote:
> On Thu, 16 Jan 2003, Nick Tonkin wrote:
> > my $dt = DateTime->parser('MySQL')->from_datetime( $mysql_dt_string );
> >
> > appears to be longer than
> >
> > my $dt = DateTime::Formats::MySQL->parse( $mysql_dt_string );
> >
> > as well as less clear.
>
> Hmm, maybe. But then I wondered what if we need to give arguments to the
> parser or formatter, and don't want to give them on every parse/format
> call. Which means that they should be object, not class methods, and the
> constructor would receive those "permanent" arguments.
Alternate reality:
use DateTime ( Defaults => {
parser => DateTime::Parser::Mysql,
parserargs => ...
});
my $dt = DateTime::parse($mysql_dt_string);
or
DateTime::parserargs(...);
my $dt = DateTime::parse($mysql_dt_string);
or
my $dt = DateTime::parse($mysql_dt_string, { parserargs => ... });
(those are not exclusive ors btw)
> > > It also has the additional side effect of allowing you to create and hold
> > > onto formatters and parsers.
my $p = DateTime::Parser::Mysql->new(...);
my $f = DateTime::Formats::Mysql->new(...);
> > Not an issue if you write a three-line function.
>
> Sure, but maybe useful in the above case.
>
> Ok, how about this then:
>
> my $format = DateTime::Formats::MySQL->new( ... );
>
> my $dt = $format->parse_datetime( $mysql_dt );
>
> $format->as_timestamp( datetime => $dt, length => 8 );
my $f = DateTime::Formats::Mysql->new(...);
my $dt = DateTime->new($mysql_dt,
{ parser => DateTime::Parser::Mysql });
print $f->as_timestamp($dt, { length => 8 });
-Scott
--
Jonathan Scott Duff
[EMAIL PROTECTED]