Re: DateTime used with Class::DBI
Answering to Rick Measham (Fri, 8 Aug 2003 10:29:08 +1000) At 4:13 PM -0700 7/8/03, Matthew McGillis wrote: [snip] Casey offers a better solution for the problem you describe, however you *could* (as apposed to should) also do the following (not the safest thing to do, but it works): In your own code put something like: *DateTime::format_how_I_want = sub { # method to turn the datetime in $_[0] into the string you need } Then in Class::DBI you can use: DateTime-format_how_I_want(); Once again, let me say (because if I don't, Dave will) that this is not recommended behaviour. It's not a good thing to play around inside other module's namespaces. Why not use subclassing? A few days ago, I attended M-J.D.'s talks in YAPC::Europe in Paris, and in one of them he just advised something like that. You do not play around somebody else's namespace, you reuse it to make your own namespace. When you remove all the buzzwords, OO is just a few good ideas, and subclassing is one of them. Jean Forget -- And now we have the World Wide Web (the only thing I know of whose shortened form --- www --- takes three times longer to say than what it¹s short for). -- Douglas Adams, the Salmon of Doubt
DateTime used with Class::DBI
I'm not sure anyone is interested but I thought I would pass this along. I have started using Class::DBI and was hoping I could also use DateTime with it. Class::DBI has some hooks to allow for any type of Object to represent Time. However the one limitation it has is that you must be able to call a method with no parameters to produce the proper output for the database. So the only way I could use DateTime with it is if $datetime-somename() produces the correct format for the database I'm using. I have taken a look at the DateTime-Format-MySQL and it can produce the formats required however with out being able to get the format through a call as described above it will never work with Class::DBI. This isn't exactly a DateTime problem or a Class::DBI problem or a Database problem just an interaction issue that someone may or may not be interested in looking at. However as the two objects operate today I don't see them being compatible. If you are interested and have any additional questions feel free to ask. Thanks Matthew McGillis
Re: DateTime used with Class::DBI
It was Thursday, August 07, 2003 when Matthew McGillis took the soap box, saying: : : I'm not sure anyone is interested but I thought I would pass this : along. I have started using Class::DBI and was hoping I could also : use DateTime with it. Class::DBI has some hooks to allow for any type : of Object to represent Time. However the one limitation it has is : that you must be able to call a method with no parameters to produce : the proper output for the database. So the only way I could use : DateTime with it is if $datetime-somename() produces the correct : format for the database I'm using. This is not true, you can also pass a code reference, any code reference. __PACKAGE__-has_a( time_stamp = 'DateTime', inflate= sub { ... }, deflate= sub { ... }, ); Casey West -- Shooting yourself in the foot with Assembly Language You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot.
Re: DateTime used with Class::DBI
* Jean Forget ([EMAIL PROTECTED]) [08 Aug 2003 16:02]: [...] Why not use subclassing? Most of the other modules return DateTime objects rather than MyDT objects. Is there a good way to get all the various support modules to return one's custom subclass without (a) subclassing all of them, (b) reblessing the output, (c) having MyDT-new_from_dt( $dt )? cheers, -- Iain.
Re: DateTime used with Class::DBI
Matthew McGillis wrote: I have taken a look at the DateTime-Format-MySQL and it can produce the formats required however with out being able to get the format through a call as described above it will never work with Class::DBI. Here's what I use in a similar situation...in the base class for my DB, the one that inherits directly from Class::DBI, I have the following: --- sub _register_dates { my $class = shift; $class = ref $class if ref $class; foreach my $column (@_) { $class-has_a( $column = 'DateTime', inflate = \_date_inflate, deflate = \_date_deflate, ) } $class; } sub _date_inflate { DateTime::Format::MySQL-parse_datetime (shift) } sub _date_deflate { DateTime::Format::MySQL-format_datetime(shift) } Then, in any table-specific classes involving MySQL datetime fields, I register the datetime columns thusly: __PACKAGE__-_register_dates(qw(date_col1 date_col2 date_col3)); Seems to work well so far. Cheers, Matt