NAME
DBIO::Timestamp - Automatically set and update timestamp columns
VERSION
version 0.900000
SYNOPSIS
package MyApp::Schema::Result::Article;
use base 'DBIO::Core';
__PACKAGE__->load_components(qw/Timestamp/);
__PACKAGE__->table('article');
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
title => { data_type => 'varchar', size => 255 },
created_at => { data_type => 'datetime', set_on_create => 1 },
updated_at => { data_type => 'datetime', set_on_create => 1, set_on_update => 1 },
);
__PACKAGE__->set_primary_key('id');
Or use the helpers to declare both standard columns in one go:
__PACKAGE__->cols_updated_created;
DESCRIPTION
Automatically populates timestamp columns on insert and update. Columns flagged with set_on_create => 1 are filled in when a new row is inserted; columns flagged with set_on_update => 1 are refreshed on every update.
Explicit values are respected: create is no-clobber, update always refreshes.
METHODS
get_timestamp
Returns a DateTime object for the current time. Override this in your Result class to customize (e.g. set a specific timezone).
col_created
__PACKAGE__->col_created; # creates 'created_at'
__PACKAGE__->col_created('born_at'); # custom name
Adds a NOT NULL timestamp column with set_on_create.
col_updated
__PACKAGE__->col_updated; # creates 'updated_at'
__PACKAGE__->col_updated('modified_at'); # custom name
Adds a NOT NULL timestamp column with set_on_create and set_on_update.
cols_updated_created
__PACKAGE__->cols_updated_created;
Adds both created_at and updated_at columns in one call.
COLUMN FLAGS
set_on_create => 1-
The column receives a fresh timestamp on insert if no value was supplied.
set_on_update => 1-
The column is refreshed on every update.
HELPER METHODS
col_created($name)-
Adds a
set_on_createtimestamp column. Default name:created_at. col_updated($name)-
Adds a column with both
set_on_createandset_on_update. Default name:updated_at. cols_updated_created-
Adds both standard columns in one call.
OVERRIDABLE METHODS
get_timestamp-
Returns a DateTime object for the current time. Override in your Result class to customize, e.g. to set a specific timezone.
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.