Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DBIx/Class/TimeStamp.pm |
Statements | Executed 227 statements in 392µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4 | 4 | 4 | 175µs | 8.88ms | add_columns | DBIx::Class::TimeStamp::
1 | 1 | 1 | 14µs | 70µs | BEGIN@3 | DBIx::Class::TimeStamp::
1 | 1 | 1 | 8µs | 17µs | BEGIN@5 | DBIx::Class::TimeStamp::
1 | 1 | 1 | 7µs | 9µs | BEGIN@6 | DBIx::Class::TimeStamp::
1 | 1 | 1 | 6µs | 6µs | BEGIN@8 | DBIx::Class::TimeStamp::
0 | 0 | 0 | 0s | 0s | get_timestamp | DBIx::Class::TimeStamp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DBIx::Class::TimeStamp; | ||||
2 | |||||
3 | 3 | 21µs | 2 | 126µs | # spent 70µs (14+56) within DBIx::Class::TimeStamp::BEGIN@3 which was called:
# once (14µs+56µs) by Class::C3::Componentised::ensure_class_loaded at line 3 # spent 70µs making 1 call to DBIx::Class::TimeStamp::BEGIN@3
# spent 56µs making 1 call to base::import |
4 | |||||
5 | 3 | 18µs | 2 | 27µs | # spent 17µs (8+9) within DBIx::Class::TimeStamp::BEGIN@5 which was called:
# once (8µs+9µs) by Class::C3::Componentised::ensure_class_loaded at line 5 # spent 17µs making 1 call to DBIx::Class::TimeStamp::BEGIN@5
# spent 9µs making 1 call to warnings::import |
6 | 3 | 18µs | 2 | 11µs | # spent 9µs (7+2) within DBIx::Class::TimeStamp::BEGIN@6 which was called:
# once (7µs+2µs) by Class::C3::Componentised::ensure_class_loaded at line 6 # spent 9µs making 1 call to DBIx::Class::TimeStamp::BEGIN@6
# spent 2µs making 1 call to strict::import |
7 | |||||
8 | 3 | 160µs | 1 | 6µs | # spent 6µs within DBIx::Class::TimeStamp::BEGIN@8 which was called:
# once (6µs+0s) by Class::C3::Componentised::ensure_class_loaded at line 8 # spent 6µs making 1 call to DBIx::Class::TimeStamp::BEGIN@8 |
9 | |||||
10 | 1 | 600ns | our $VERSION = '0.14'; | ||
11 | |||||
12 | 1 | 8µs | 1 | 0s | __PACKAGE__->load_components( qw/DynamicDefault InflateColumn::DateTime/ ); # spent 1.27ms making 1 call to Class::C3::Componentised::load_components, recursion: max depth 1, sum of overlapping time 1.27ms |
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 | # spent 8.88ms (175µs+8.71) within DBIx::Class::TimeStamp::add_columns which was called 4 times, avg 2.22ms/call:
# once (72µs+4.18ms) by Class::C3::Componentised::ensure_class_loaded at line 19 of Tapper/Schema/ReportsDB/Result/Report.pm
# once (37µs+1.79ms) by Class::C3::Componentised::ensure_class_loaded at line 17 of Tapper/Schema/ReportsDB/Result/ReportFile.pm
# once (33µs+1.54ms) by Class::C3::Componentised::ensure_class_loaded at line 19 of Tapper/Schema/ReportsDB/Result/Tap.pm
# once (33µs+1.20ms) by Class::C3::Componentised::ensure_class_loaded at line 16 of Tapper/Schema/ReportsDB/Result/ReportComment.pm | ||||
45 | 4 | 16µs | my ($self, @cols) = @_; | ||
46 | 4 | 2µs | my @columns; | ||
47 | |||||
48 | 4 | 29µs | while (my $col = shift @cols) { | ||
49 | 47 | 18µs | my $info = ref $cols[0] ? shift @cols : {}; | ||
50 | |||||
51 | 47 | 20µs | if ( delete $info->{set_on_create} ) { | ||
52 | $info->{dynamic_default_on_create} = 'get_timestamp'; | ||||
53 | } | ||||
54 | |||||
55 | 47 | 13µs | if ( delete $info->{set_on_update} ) { | ||
56 | 4 | 3µs | $info->{dynamic_default_on_update} = 'get_timestamp'; | ||
57 | |||||
58 | 4 | 6µs | 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 | 47 | 27µs | push @columns, $col => $info; | ||
66 | } | ||||
67 | |||||
68 | 4 | 30µs | 4 | 39µs | return $self->next::method(@columns); # spent 39µs making 4 calls to next::method, avg 10µs/call |
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 <jshirley@gmail.com> | ||||
90 | |||||
91 | =head1 CONTRIBUTORS | ||||
92 | |||||
93 | Florian Ragwitz (Porting to L<DBIx::Class::DynamicDefault>) | ||||
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 | 5µs | 1; | ||
107 |