* Dave Rolsky ([EMAIL PROTECTED]) [20 Mar 2003 16:43]:
> On Thu, 20 Mar 2003, Iain 'Spoon' Truskett wrote:
[...]
> > DateTime::Format::(Builder|Generic|Factory) (I forget what the
> > patterns folk are into these days)
> I think it'd be Builder, since what it should probably do is construct
> methods for you based on a spec.
Sounds good.
> > > my $custom_parser = DateTime::Format::Custom->format(
> > > 15 => {
> > > params => [ qw( year month day hour minute second ) ],
> > > regex => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
> > > zero => {},
> > > },
> > > ...
> > > );
> >
> > Not sure I'd have the '15' bit there. Or is that to let it try
> > multiple parses?
> The 15 is the string length. In this example, taken from the iCal
> format module, it checks the string length and parses based on that,
> since there are several valid iCal formats each of which is
> distinguishable based on length.
Yeah. I got that =) I was just wondering what the applicability in
DateTime::Format::Builder would be.
I can see a use in, say, having an array of them. As in: try this first,
then this, then this, or fail.
A hash could be useful if order isn't important, and for reporting a
name in some sort of verbose mode:
$custom_parser->parse_date( "Quetzal" );
# Parsed as "SavedGame" type. (as a warn or something)
> I think what struck Joshua was the extreme similarity between this,
> the MySQL, and the W3CDTF module.
And, I expect, many more to come. We may well end up with a
DateTime::Format::Common. e.g.:
my $mysql = DateTime::Format::Common->new( class => 'mysql' );
my $mysqlstamp = DateTime::Format::Common->new(
class => 'mysql', parser => 'timestamp' );
Or something. No, I'm not fond of the arguments I just wrote.
Theoretically, with a library of the things, you could write a
DateTime::Format::AttemptAll:
my $parser = DateTime::Format::AttemptAll->new(
output => DateTime::Format::Excel->new );
my $dt = $parser->parse_date( $some_unknown_string );
print $parser->format_date( $dt );
where AttemptAll would create a bunch of the parser and try them in a
series. Not fast, but potentially effective.
Or maybe:
my $chain = DateTime::Format::Chain->new( parsers => [
DateTime::Format::Excel->new(),
DateTime::Format::Baby->new(),
DateTime::Format::W3CDTF->new(),
]);
Hmm.
> If someone wants to work on a Builder module, that's fine with me.
I'll be having a play. No guarantees.
cheers,
--
Iain.