1DBIx::Class::InflateColUusmenr(3C)ontributed Perl DocumeDnBtIaxt:i:oCnlass::InflateColumn(3)
2
3
4
6 DBIx::Class::InflateColumn - Automatically create references from
7 column data
8
10 # In your table classes
11 __PACKAGE__->inflate_column('column_name', {
12 inflate => sub { ... },
13 deflate => sub { ... },
14 });
15
17 This component translates column data into references, i.e. "inflating"
18 the column data. It also "deflates" references into an appropriate
19 format for the database.
20
21 It can be used, for example, to automatically convert to and from
22 DateTime objects for your date and time fields. There's a convenience
23 component to actually do that though, try
24 DBIx::Class::InflateColumn::DateTime.
25
26 It will handle all types of references except scalar references. It
27 will not handle scalar values, these are ignored and thus passed
28 through to SQL::Abstract. This is to allow setting raw values to "just
29 work". Scalar references are passed through to the database to deal
30 with, to allow such settings as " \'year + 1'" and " \'DEFAULT' " to
31 work.
32
33 If you want to filter plain scalar values and replace them with
34 something else, contribute a filtering component.
35
37 inflate_column
38 Instruct DBIx::Class to inflate the given column.
39
40 In addition to the column name, you must provide "inflate" and
41 "deflate" methods. The "inflate" method is called when you access the
42 field, while the "deflate" method is called when the field needs to
43 used by the database.
44
45 For example, if you have a table "events" with a timestamp field named
46 "insert_time", you could inflate the column in the corresponding table
47 class using something like:
48
49 __PACKAGE__->inflate_column('insert_time', {
50 inflate => sub { DateTime::Format::Pg->parse_datetime(shift); },
51 deflate => sub { DateTime::Format::Pg->format_datetime(shift); },
52 });
53
54 (Replace DateTime::Format::Pg with the appropriate module for your
55 database, or consider DateTime::Format::DBI.)
56
57 The coderefs you set for inflate and deflate are called with two
58 parameters, the first is the value of the column to be
59 inflated/deflated, the second is the row object itself. Thus you can
60 call "->result_source->schema->storage->dbh" in your inflate/defalte
61 subs, to feed to DateTime::Format::DBI.
62
63 In this example, calls to an event's "insert_time" accessor return a
64 DateTime object. This DateTime object is later "deflated" when used in
65 the database layer.
66
67 get_inflated_column
68 my $val = $obj->get_inflated_column($col);
69
70 Fetch a column value in its inflated state. This is directly analogous
71 to "get_column" in DBIx::Class::Row in that it only fetches a column
72 already retrieved from the database, and then inflates it. Throws an
73 exception if the column requested is not an inflated column.
74
75 set_inflated_column
76 my $copy = $obj->set_inflated_column($col => $val);
77
78 Sets a column value from an inflated value. This is directly analogous
79 to "set_column" in DBIx::Class::Row.
80
81 store_inflated_column
82 my $copy = $obj->store_inflated_column($col => $val);
83
84 Sets a column value from an inflated value without marking the column
85 as dirty. This is directly analogous to "store_column" in
86 DBIx::Class::Row.
87
89 DBIx::Class::Core - This component is loaded as part of the "core"
90 DBIx::Class components; generally there is no need to load it directly
91
93 Matt S. Trout <mst@shadowcatsystems.co.uk>
94
96 Daniel Westermann-Clark <danieltwc@cpan.org> (documentation)
97
98 Jess Robinson <cpan@desert-island.demon.co.uk>
99
101 You may distribute this code under the same terms as Perl itself.
102
103
104
105perl v5.12.0 2010-05-12 DBIx::Class::InflateColumn(3)