jaldhar has asked for the wisdom of the Perl Monks concerning the following question:
Normally when I test an application that makes use of times, I turn to Test::MockTime which works wonderfully for setting Perls notions of the current time to arbitrary values. In this app, however it doesn't work because the database has the following fields:
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CREATE TRIGGER IF NOT EXISTS update_modification_time AFTER UPDATE OF title, body ON items FOR EACH ROW BEGIN UPDATE items SET modified = DATETIME('NOW') WHERE id = new +.id; END;
Modules like Test::MockTime work by intercepting Perls time related functions but here the time is being set by the SQLite library (calling down to libc functions no doubt) and so this approach does not work. I can think of two possible alternatives:
There are C preload libraries like faketime which intercept C library time functions. Can something like that be used from within a Perl script?
DBD::SQlite lets you use sqlite_create_function. Could this be used to override SQLites time related functions? If so which ones?
Comments welcome on whether either of these ideas are feasable or if there are better solutions.