| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Class::TimeStamp; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
466
|
use base qw(DBIx::Class); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
429
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
42977
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
40
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
224
|
use DateTime; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->load_components( qw/DynamicDefault InflateColumn::DateTime/ ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
DBIx::Class::TimeStamp - DBIx::Class extension to update and create date and time based fields |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Works in conjunction with InflateColumn::DateTime to automatically set update |
|
21
|
|
|
|
|
|
|
and create date and time based fields in a table. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package My::Schema; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw( TimeStamp ... Core )); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__PACKAGE__->add_columns( |
|
30
|
|
|
|
|
|
|
id => { data_type => 'integer' }, |
|
31
|
|
|
|
|
|
|
t_created => { data_type => 'datetime', set_on_create => 1 }, |
|
32
|
|
|
|
|
|
|
t_updated => { data_type => 'datetime', |
|
33
|
|
|
|
|
|
|
set_on_create => 1, set_on_update => 1 }, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Now, any update or create actions will update the specified columns with the |
|
37
|
|
|
|
|
|
|
current time, using the DateTime inflator. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is effectively trigger emulation to get consistent behavior across |
|
40
|
|
|
|
|
|
|
databases that either implement them poorly or not at all. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add_columns { |
|
45
|
|
|
|
|
|
|
my ($self, @cols) = @_; |
|
46
|
|
|
|
|
|
|
my @columns; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
while (my $col = shift @cols) { |
|
49
|
|
|
|
|
|
|
my $info = ref $cols[0] ? shift @cols : {}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
if ( delete $info->{set_on_create} ) { |
|
52
|
|
|
|
|
|
|
$info->{dynamic_default_on_create} = 'get_timestamp'; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if ( delete $info->{set_on_update} ) { |
|
56
|
|
|
|
|
|
|
$info->{dynamic_default_on_update} = 'get_timestamp'; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( defined $info->{dynamic_default_on_create} and |
|
59
|
|
|
|
|
|
|
$info->{dynamic_default_on_create} eq 'get_timestamp' |
|
60
|
|
|
|
|
|
|
) { |
|
61
|
|
|
|
|
|
|
$info->{dynamic_default_on_update} = 'get_timestamp'; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
push @columns, $col => $info; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $self->next::method(@columns); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 METHODS |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 get_timestamp |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Returns a DateTime object pointing to now. Override this method if you have |
|
76
|
|
|
|
|
|
|
different time accounting functions, or want to do anything special. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The date and time objects in the database are expected to be inflated. As such |
|
79
|
|
|
|
|
|
|
you can be pretty flexible with what you want to return here. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_timestamp { |
|
84
|
|
|
|
|
|
|
return DateTime->now |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
J. Shirley |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Florian Ragwitz (Porting to L) |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
LTJake/bricas |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Copyright 2009 J. Shirley, all rights reserved. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
102
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
|
107
|
|
|
|
|
|
|
|