On Wed, 28 Mar 2007, Rick Measham wrote:

Boorstein, Daniel B wrote:
I realize this is my problem since I broke encapsulation, but I'm
wondering if others have dealt with this already. Is there a designated
means for derived classes to add custom instance data? I've perused the
docs, but didn't see anything specific for authors of derived classes.

There's been a few times where I wanted to hang data off a DT, especially for DT::Event modules

Someone had proposed a while back that DT::Event modules support returning an object that contains additional info beyond the datetime. I'd like to pursue that (or have _someone_ pursue it ;)

I'd suggest we have a purpose built $self->{data} for hanging such stuff and make sure that anything in there is preserved across mutations and clonings.

I really don't think this data belongs in the DateTime object. There's something odd about the idea that two otherwise "identical" objects could have different data under the hood, where one knows about an event and one doesn't.

Here's some ideas ...

All datetime-returning methods in event modules should return two objects in list context:

 my ( $dt, $event ) = $events->next();

Or maybe event modules support some sort API where you give it a datetime and it tells you something about it:

 my $event = $event->info_for_datetime($dt);

I'm kind of leaning towards the latter.

There's some open questions:

* What is $event? Is it an object, a hashref, what? Maybe it's different for each event module? * How do modules that don't have anything extra to say express that? undef? a special null object?


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to