Commit | Line | Data |
c6d74d3e |
1 | package # hide from PAUSE |
2 | Log; |
ea2e61bf |
3 | |
ea2e61bf |
4 | use base 'MyBase'; |
5 | |
6 | use strict; |
7 | use Time::Piece::MySQL; |
8 | use POSIX; |
9 | |
10 | __PACKAGE__->set_table(); |
11 | __PACKAGE__->columns(All => qw/id message datetime_stamp/); |
12 | __PACKAGE__->has_a( |
13 | datetime_stamp => 'Time::Piece', |
14 | inflate => 'from_mysql_datetime', |
15 | deflate => 'mysql_datetime' |
16 | ); |
17 | |
18 | __PACKAGE__->add_trigger(before_create => \&set_dts); |
19 | __PACKAGE__->add_trigger(before_update => \&set_dts); |
20 | |
21 | sub set_dts { |
22 | shift->datetime_stamp( |
23 | POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime(time))); |
24 | } |
25 | |
26 | sub create_sql { |
27 | return qq{ |
28 | id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, |
29 | message VARCHAR(255), |
30 | datetime_stamp DATETIME |
31 | }; |
32 | } |
33 | |
34 | 1; |
35 | |