1DBIx::Class::DynamicDefUasuelrt(C3o)ntributed Perl DocumDeBnItxa:t:iColnass::DynamicDefault(3)
2
3
4

NAME

6       DBIx::Class::DynamicDefault - Automatically set and update fields
7

SYNOPSIS

9         package My::Schema::SomeTable;
10
11         __PACKAGE__->load_components(qw/DynamicDefault ... Core/);
12
13         __PACKAGE__->add_columns(
14                 quux          => { data_type => 'integer' },
15                 quux_plus_one => { data_type => 'integer',
16                                    dynamic_default_on_create => \&quux_plus_one_default,
17                                    dynamic_default_on_update => 'quux_plus_one_default', },
18                 last_changed  => { data_type => 'integer',
19                                    dynamic_default_on_create => 'now',
20                                    dynamic_default_on_update => 'now, },
21         );
22
23         sub quux_plus_one_default {
24             my ($self) = @_;
25             return $self->quux + 1;
26         }
27
28         sub now {
29             return DateTime->now->epoch;
30         }
31
32       Now, any update or create actions will set the specified columns to the
33       value returned by the callback you specified as a method name or code
34       reference.
35

DESCRIPTION

37       Automatically set and update fields with values calculated at runtime.
38

OPTIONS

40   dynamic_default_on_create
41         dynamic_default_on_create => sub { ... }
42
43         dynamic_default_on_create => 'method_name'
44
45       When inserting a new row all columns with the
46       "dynamic_default_on_create" option will be set to the return value of
47       the specified callback unless the columns value has been explicitly
48       set. The callback, that'll be invoked with the row object as its only
49       argument, may be a code reference or a method name.
50
51   dynamic_default_on_update
52         dynamic_default_on_update => sub { ... }
53
54         dynamic_default_on_update => 'method_name'
55
56       When updating a row all columns with the "dynamic_default_on_update"
57       option will be set to the return value of the specified callback unless
58       the columns value has been explicitly set.
59
60       Columns will only be altered if other dirty columns exist. See
61       "always_update" on how to change this.
62
63   always_update
64         always_update => 1
65
66       When setting "always_update" to 1 "dynamic_default_on_update" callbacks
67       will always be invoked, even if no other columns are dirty.
68

AUTHOR

70       Florian Ragwitz <rafl@debian.org>
71

LICENSE

73       This software is copyright (c) 2008 by Florian Ragwitz.
74
75       This is free software; you can redistribute it and/or modify it under
76       the same terms as perl itself.
77
78
79
80perl v5.36.0                      2022-07-22    DBIx::Class::DynamicDefault(3)
Impressum