.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DBIx::Class::DynamicDefault 3pm" .TH DBIx::Class::DynamicDefault 3pm "2022-06-13" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::Class::DynamicDefault \- Automatically set and update fields .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package My::Schema::SomeTable; \& \& _\|_PACKAGE_\|_\->load_components(qw/DynamicDefault ... Core/); \& \& _\|_PACKAGE_\|_\->add_columns( \& quux => { data_type => \*(Aqinteger\*(Aq }, \& quux_plus_one => { data_type => \*(Aqinteger\*(Aq, \& dynamic_default_on_create => \e&quux_plus_one_default, \& dynamic_default_on_update => \*(Aqquux_plus_one_default\*(Aq, }, \& last_changed => { data_type => \*(Aqinteger\*(Aq, \& dynamic_default_on_create => \*(Aqnow\*(Aq, \& dynamic_default_on_update => \*(Aqnow, }, \& ); \& \& sub quux_plus_one_default { \& my ($self) = @_; \& return $self\->quux + 1; \& } \& \& sub now { \& return DateTime\->now\->epoch; \& } .Ve .PP Now, any update or create actions will set the specified columns to the value returned by the callback you specified as a method name or code reference. .SH "DESCRIPTION" .IX Header "DESCRIPTION" Automatically set and update fields with values calculated at runtime. .SH "OPTIONS" .IX Header "OPTIONS" .SS "dynamic_default_on_create" .IX Subsection "dynamic_default_on_create" .Vb 1 \& dynamic_default_on_create => sub { ... } \& \& dynamic_default_on_create => \*(Aqmethod_name\*(Aq .Ve .PP When inserting a new row all columns with the \f(CW\*(C`dynamic_default_on_create\*(C'\fR option will be set to the return value of the specified callback unless the columns value has been explicitly set. The callback, that'll be invoked with the row object as its only argument, may be a code reference or a method name. .SS "dynamic_default_on_update" .IX Subsection "dynamic_default_on_update" .Vb 1 \& dynamic_default_on_update => sub { ... } \& \& dynamic_default_on_update => \*(Aqmethod_name\*(Aq .Ve .PP When updating a row all columns with the \f(CW\*(C`dynamic_default_on_update\*(C'\fR option will be set to the return value of the specified callback unless the columns value has been explicitly set. .PP Columns will only be altered if other dirty columns exist. See \f(CW\*(C`always_update\*(C'\fR on how to change this. .SS "always_update" .IX Subsection "always_update" .Vb 1 \& always_update => 1 .Ve .PP When setting \f(CW\*(C`always_update\*(C'\fR to 1 \f(CW\*(C`dynamic_default_on_update\*(C'\fR callbacks will always be invoked, even if no other columns are dirty. .SH "AUTHOR" .IX Header "AUTHOR" Florian Ragwitz .SH "LICENSE" .IX Header "LICENSE" This software is copyright (c) 2008 by Florian Ragwitz. .PP This is free software; you can redistribute it and/or modify it under the same terms as perl itself.