1DBIx::Class::InflateColUusmenr(3C)ontributed Perl DocumeDnBtIaxt:i:oCnlass::InflateColumn(3)
2
3
4

NAME

6       DBIx::Class::InflateColumn - Automatically create references from
7       column data
8

SYNOPSIS

10         # In your table classes
11         __PACKAGE__->inflate_column('column_name', {
12           inflate => sub {
13             my ($raw_value_from_db, $result_object) = @_;
14             ...
15           },
16           deflate => sub {
17             my ($inflated_value_from_user, $result_object) = @_;
18             ...
19           },
20         });
21

DESCRIPTION

23       This component translates column data into references, i.e. "inflating"
24       the column data. It also "deflates" references into an appropriate
25       format for the database.
26
27       It can be used, for example, to automatically convert to and from
28       DateTime objects for your date and time fields. There's a convenience
29       component to actually do that though, try
30       DBIx::Class::InflateColumn::DateTime.
31
32       It will handle all types of references except scalar references. It
33       will not handle scalar values, these are ignored and thus passed
34       through to SQL::Abstract::Classic. This is to allow setting raw values
35       to "just work". Scalar references are passed through to the database to
36       deal with, to allow such settings as " \'year + 1'" and " \'DEFAULT' "
37       to work.
38
39       If you want to filter plain scalar values and replace them with
40       something else, see DBIx::Class::FilterColumn.
41

METHODS

43   inflate_column
44       Instruct DBIx::Class to inflate the given column.
45
46       In addition to the column name, you must provide "inflate" and
47       "deflate" methods. The "inflate" method is called when you access the
48       field, while the "deflate" method is called when the field needs to
49       used by the database.
50
51       For example, if you have a table "events" with a timestamp field named
52       "insert_time", you could inflate the column in the corresponding table
53       class using something like:
54
55           __PACKAGE__->inflate_column('insert_time', {
56               inflate => sub {
57                 my ($insert_time_raw_value, $event_result_object) = @_;
58                 DateTime->from_epoch( epoch => $insert_time_raw_value );
59               },
60               deflate => sub {
61                 my ($insert_time_dt_object, $event_result_object) = @_;
62                 $insert_time_dt_object->epoch;
63               },
64           });
65
66       The coderefs you set for inflate and deflate are called with two
67       parameters, the first is the value of the column to be
68       inflated/deflated, the second is the result object itself.
69
70       In this example, calls to an event's "insert_time" accessor return a
71       DateTime object. This DateTime object is later "deflated" back to the
72       integer epoch representation when used in the database layer.  For a
73       much more thorough handling of the above example, please see
74       DBIx::Class::DateTime::Epoch
75
76   get_inflated_column
77         my $val = $obj->get_inflated_column($col);
78
79       Fetch a column value in its inflated state.  This is directly analogous
80       to "get_column" in DBIx::Class::Row in that it only fetches a column
81       already retrieved from the database, and then inflates it.  Throws an
82       exception if the column requested is not an inflated column.
83
84   set_inflated_column
85         my $copy = $obj->set_inflated_column($col => $val);
86
87       Sets a column value from an inflated value.  This is directly analogous
88       to "set_column" in DBIx::Class::Row.
89
90   store_inflated_column
91         my $copy = $obj->store_inflated_column($col => $val);
92
93       Sets a column value from an inflated value without marking the column
94       as dirty. This is directly analogous to "store_column" in
95       DBIx::Class::Row.
96

SEE ALSO

98       DBIx::Class::Core - This component is loaded as part of the "core"
99       DBIx::Class components; generally there is no need to load it directly
100

FURTHER QUESTIONS?

102       Check the list of additional DBIC resources.
103
105       This module is free software copyright by the DBIx::Class (DBIC)
106       authors. You can redistribute it and/or modify it under the same terms
107       as the DBIx::Class library.
108
109
110
111perl v5.32.0                      2020-07-28     DBIx::Class::InflateColumn(3)
Impressum