README
1NAME
2 DBIx::Class::VirtualColumns - Add virtual columns to DBIx::Class
3 schemata
4
5SYNOPSIS
6 package Your::Schema::Class;
7 use strict;
8 use warnings;
9
10 use base 'DBIx::Class';
11
12 __PACKAGE__->load_components(
13 "VirtualColumns",
14 "PK",
15 "Core",
16 );
17
18 __PACKAGE__->table("sometable");
19 __PACKAGE__->add_columns(qw/dbcol1 dbcol2/);
20 __PACKAGE__->add_virtual_columns(qw/vcol1 vcol2 vcol3/);
21
22 # =========================================================
23 # Somewhere else
24
25 my $item = $schema->resultset('Artist')->find($id);
26 $item->vcol1('test'); # Set 'test'
27 $item->get_column('vcol1'); # Return 'test'
28
29 my $otheritem = $schema->resultset('Artist')->create({
30 dbcol1 => 'value1',
31 dbcol2 => 'value2',
32 vcol1 => 'value3',
33 vcol2 => 'value4',
34 });
35
36 $otheritem->vcol1(); # Now is 'value3'
37
38 # Get the column metadata just like for a regular DBIC column
39 my $info = $result_source->column_info('vcol1');
40
41DESCRIPTION
42 This module allows to specify 'virtual columns' in DBIx::Class schema
43 classes. Virtual columns behave almost like regular columns but are not
44 stored in the database. They may be used to store temporary information
45 in the DBIx::Class::Row object and without introducting an additional
46 interface.
47
48 Most DBIx::Class methods like "set_column", "set_columns", "get_column",
49 "get_columns", "column_info", ... will work with regular as well as
50 virtual columns.
51
52USAGE
53 Use this module if you want to add 'virtual' columns to a DBIC class
54 which behave like real columns (e.g. if you want to use the
55 "set_column", "get_column" methods)
56
57 However if you only want to add non-column data to DBIx::Class::Row
58 objects, then there are easier/better ways:
59
60 __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz));
61
62METHODS
63 add_virtual_columns
64 Adds virtual columns to the result source. If supplied key => hashref
65 pairs, uses the hashref as the column_info for that column. Repeated
66 calls of this method will add more columns, not replace them.
67
68 $table->add_virtual_columns(qw/column1 column2/);
69 OR
70 $table->add_virtual_columns(column1 => \%column1_info, column2 => \%column2_info, ...);
71
72 The column names given will be created as accessor methods on your
73 "DBIx::Class::Row objects", you can change the name of the accessor by
74 supplying an "accessor" in the column_info hash.
75
76 The following options are currently recognised/used by
77 DBIx::Class::VirtualColumns:
78
79 * accessor
80
81 Use this to set the name of the accessor method for this column. If
82 not set, the name of the column will be used.
83
84 add_virtual_column
85 Shortcut for add_virtual_columns
86
87 has_any_column
88 Returns true if the source has a virtual or regular column of this name,
89 false otherwise.
90
91 has_virtual_column
92 Returns true if the source has a virtual column of this name, false
93 otherwise.
94
95 remove_virtual_columns
96 $table->remove_columns(qw/col1 col2 col3/);
97
98 Removes virtual columns from the result source.
99
100 remove_virtual_column
101 Shortcut for remove_virtual_columns
102
103 _virtual_filter
104 Splits attributes for regular and virtual columns
105
106 new
107 Overloaded method. "new" in DBIx::Class::Row
108
109 get_column
110 Overloaded method. "get_colum" in DBIx::Class::Row
111
112 get_columns
113 Overloaded method. "get_colums" in DBIx::Class::Row
114
115 store_column
116 Overloaded method. "store_column" in DBIx::Class::Row
117
118 set_column
119 Overloaded method. "set_column" in DBIx::Class::Row
120
121 column_info
122 Overloaded method. "column_info" in DBIx::Class::ResultSource
123
124 Additionally returns the HASH key 'virtual' which indicates if the
125 requested column is virtual or not.
126
127 update
128 Overloaded method. "update" in DBIx::Class::Row
129
130CAVEATS
131 The best way to add non-column data to DBIC objects is to use
132 Class::Accessor::Grouped.
133
134 __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz));
135
136 Use DBIx::Class::VirtualColumns only if you rely on DBIx::Class::Row
137 methods like "set_column", "get_column", ...
138
139SUPPORT
140 This module was just a proof of concept, and is not actively developed
141 anymore. Patches are still welcome though.
142
143 Please report any bugs to "bug-dbix-class-virtualcolumns@rt.cpan.org",
144 or through the web interface at
145 <http://rt.cpan.org/Public/Bug/Report.html?Queue=DBIx::Class::VirtualCol
146 umns>. I will be notified, and then you'll automatically be notified of
147 progress on your report as I make changes.
148
149AUTHOR
150 Maroš Kollár
151 CPAN ID: MAROS
152 maros [at] k-1.com
153 L<http://www.revdev.at>
154
155ACKNOWLEDGEMENTS
156 This module was written for Revdev <http://www.revdev.at>, a nice litte
157 software company I run with Koki and Domm
158 (<http://search.cpan.org/~domm/>).
159
160COPYRIGHT
161 DBIx::Class::VirtualColumns is Copyright (c) 2008 Maroš Kollár -
162 <http://www.revdev.at>
163
164 This program is free software; you can redistribute it and/or modify it
165 under the same terms as Perl itself.
166
167 The full text of the license can be found in the LICENSE file included
168 with this module.
169
170
README.mkdn
1# NAME
2
3DBIx::Class::VirtualColumns - Add virtual columns to DBIx::Class schemata
4
5# SYNOPSIS
6
7 package Your::Schema::Class;
8 use strict;
9 use warnings;
10
11
12 use base 'DBIx::Class';
13
14
15 __PACKAGE__->load_components(
16 "VirtualColumns",
17 "PK",
18 "Core",
19 );
20
21
22 __PACKAGE__->table("sometable");
23 __PACKAGE__->add_columns(qw/dbcol1 dbcol2/);
24 __PACKAGE__->add_virtual_columns(qw/vcol1 vcol2 vcol3/);
25
26
27 # =========================================================
28 # Somewhere else
29
30
31 my $item = $schema->resultset('Artist')->find($id);
32 $item->vcol1('test'); # Set 'test'
33 $item->get_column('vcol1'); # Return 'test'
34
35
36 my $otheritem = $schema->resultset('Artist')->create({
37 dbcol1 => 'value1',
38 dbcol2 => 'value2',
39 vcol1 => 'value3',
40 vcol2 => 'value4',
41 });
42
43
44 $otheritem->vcol1(); # Now is 'value3'
45
46
47 # Get the column metadata just like for a regular DBIC column
48 my $info = $result_source->column_info('vcol1');
49
50# DESCRIPTION
51
52This module allows to specify 'virtual columns' in DBIx::Class schema
53classes. Virtual columns behave almost like regular columns but are not
54stored in the database. They may be used to store temporary information in
55the [DBIx::Class::Row](http://search.cpan.org/search?mode=module&query=DBIx::Class::Row) object and without introducting an additional
56interface.
57
58Most [DBIx::Class](http://search.cpan.org/search?mode=module&query=DBIx::Class) methods like `set_column`, `set_columns`, `get_column`,
59`get_columns`, `column_info`, ... will work with regular as well as
60virtual columns.
61
62# USAGE
63
64Use this module if you want to add 'virtual' columns to a DBIC class
65which behave like real columns (e.g. if you want to use the `set_column`,
66`get_column` methods)
67
68However if you only want to add non-column data to [DBIx::Class::Row](http://search.cpan.org/search?mode=module&query=DBIx::Class::Row)
69objects, then there are easier/better ways:
70
71 __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz));
72
73# METHODS
74
75## add_virtual_columns
76
77Adds virtual columns to the result source. If supplied key => hashref pairs,
78uses the hashref as the column_info for that column. Repeated calls of this
79method will add more columns, not replace them.
80
81 $table->add_virtual_columns(qw/column1 column2/);
82 OR
83 $table->add_virtual_columns(column1 => \%column1_info, column2 => \%column2_info, ...);
84
85The column names given will be created as accessor methods on your
86`DBIx::Class::Row objects`, you can change the name of the accessor by
87supplying an "accessor" in the column_info hash.
88
89The following options are currently recognised/used by
90DBIx::Class::VirtualColumns:
91
92- * accessor
93
94Use this to set the name of the accessor method for this column. If not set,
95the name of the column will be used.
96
97## add_virtual_column
98
99Shortcut for [add_virtual_columns](http://search.cpan.org/search?mode=module&query=add_virtual_columns)
100
101## has_any_column
102
103Returns true if the source has a virtual or regular column of this name,
104false otherwise.
105
106## has_virtual_column
107
108Returns true if the source has a virtual column of this name, false otherwise.
109
110## remove_virtual_columns
111
112 $table->remove_columns(qw/col1 col2 col3/);
113
114
115Removes virtual columns from the result source.
116
117## remove_virtual_column
118
119Shortcut for [remove_virtual_columns](http://search.cpan.org/search?mode=module&query=remove_virtual_columns)
120
121## _virtual_filter
122
123Splits attributes for regular and virtual columns
124
125## new
126
127Overloaded method. L<DBIx::Class::Row/"new">
128
129## get_column
130
131Overloaded method. L<DBIx::Class::Row/"get_colum">
132
133## get_columns
134
135Overloaded method. L<DBIx::Class::Row/"get_colums">
136
137## store_column
138
139Overloaded method. L<DBIx::Class::Row/"store_column">
140
141## set_column
142
143Overloaded method. L<DBIx::Class::Row/"set_column">
144
145## column_info
146
147Overloaded method. L<DBIx::Class::ResultSource/"column_info">
148
149Additionally returns the HASH key 'virtual' which indicates if the requested
150column is virtual or not.
151
152## update
153
154Overloaded method. L<DBIx::Class::Row/"update">
155
156# CAVEATS
157
158The best way to add non-column data to DBIC objects is to use
159[Class::Accessor::Grouped](http://search.cpan.org/search?mode=module&query=Class::Accessor::Grouped).
160
161 __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz));
162
163Use [DBIx::Class::VirtualColumns](http://search.cpan.org/search?mode=module&query=DBIx::Class::VirtualColumns) only if you rely on [DBIx::Class::Row](http://search.cpan.org/search?mode=module&query=DBIx::Class::Row)
164methods like `set_column`, `get_column`, ...
165
166# SUPPORT
167
168This module was just a proof of concept, and is not actively developed
169anymore. Patches are still welcome though.
170
171Please report any bugs to
172`bug-dbix-class-virtualcolumns@rt.cpan.org`, or through the web interface at
173<http://rt.cpan.org/Public/Bug/Report.html?Queue=DBIx::Class::VirtualColumns>.
174I will be notified, and then you'll automatically be notified of progress on
175your report as I make changes.
176
177# AUTHOR
178
179 Maroš Kollár
180 CPAN ID: MAROS
181 maros [at] k-1.com
182 L<http://www.revdev.at>
183
184# ACKNOWLEDGEMENTS
185
186This module was written for Revdev <http://www.revdev.at>, a nice litte
187software company I run with Koki and Domm (<http://search.cpan.org/~domm/>).
188
189# COPYRIGHT
190
191DBIx::Class::VirtualColumns is Copyright (c) 2008 Maroš Kollár
192- <http://www.revdev.at>
193
194This program is free software; you can redistribute it and/or modify it under
195the same terms as Perl itself.
196
197The full text of the license can be found in the
198LICENSE file included with this module.