* Ben Bennett ([EMAIL PROTECTED]) [25 Jun 2003 23:06]:
> On Wed, Jun 25, 2003 at 06:53:10PM +1000, Iain Truskett wrote:
> > * Joshua Hoblitt ([EMAIL PROTECTED]) [25 Jun 2003 17:59]:
> >
> > > But what if I use /(-?\d\d\d\d)/ as the regex and set the
> > > length => [ qw( 4 5 ) ]? :)
> >
> > cvs update
> >
> > Your wish is my small patch.
> While you are fiddling with the lengths...
> Ok. One of the reasons that I am not using Builder is for the length
> greater than N cases...
> For example ISO8601 has fractional formats, e.g.:
> HH:MM:SS.ssss...
> I want to be able to say this is a valid match if the length is 10 or
> more characters.
Hmm. Using Joshua's new features:
use DateTime::Format::Builder
(
parsers => {
parse_fractional => {
Dispatch => sub {
return 'longer_than_nine' if length $_[0] > 10;
return;
}
}
},
groups => {
longer_than_nine => [
{
regex => qr{^(\d\d):(\d\d):(\d\d)\.(\d+)$},
params => [qw( hour minute second something )],
}
]
}
);
Of course, many things may be longer than 10 chars. Of course, we can't
jump straight to the right set of parsers, but it's fairly close to a
direct jump.
> Of course the other reason that I am not using Builder at the moment
> is that I allow the user to specify the types of formats that they
> want to consider and making that work in the Builder framework seemed
> to be more trouble than it was worth.
I think you'll find the new Dispatch code will let you do that sort of
thing.
{
Dispatch => sub {
my @groups = qw( standard );
push @groups, 'extended' if something;
return @groups;
},
}
I can easily have the Dispatch sub be given extra arguments if you like.
I should probably be giving it $self anyway. Would that be helpful?
Of course, there's no need for anyone to use Builder if they don't want
to. It's just there to simplify a lot of cases. Indeed, some of the bits
can be happily used without needing the 'whole class dependent on
Builder' method I usually use in examples. You can just use it to create
coderefs that either return a DateTime or undef. Which may or may not be
useful.
Groups can currently only be declared globally though. However since you
can happily feed it "parsers => {}" that may not be a problem.
But I don't want it to seem like I'm pushing Builder onto people. Don't
use it if you don't want to. But if it doesn't fit your needs, I am
interested in hearing about them.
cheers,
--
Iain. <http://eh.org/~koschei/>