SPOPS::Tool::DBI::DiscoverField - SPOPS::ClassFactory rule implementing autofield discovery
my $config = { myobject => { class => 'My::Object', isa => [ 'SPOPS::DBI' ], field => [], # just for show... rules_from => [ 'My::DiscoverField' ], field_discover => 'yes', base_table => 'mydata', ... }, }; my $class_list = SPOPS::Initialize->process({ config => $config }); # All fields in 'mydata' table now available as object properties
Simple behavior rule to dynamically find all fields in a particular database table and set them in our object.
Configuration is easy, just put:
rules_from => [ 'My::DiscoverField' ],
in your object configuration, or add 'My::DiscoverField' to an already-existing 'rules_from' list. Then add:
field_discover => 'yes',
to your object configuration. Initialize the class and everything in 'field' will be overwritten.
These fields are only discovered once, when the class is created. If you modify the schema of a table (such as with an 'ALTER TABLE' statement while a process (like a webserver) is running with SPOPS definitions the field modifications will not be reflected in the object class definition. (This is actually true of all SPOPS::DBI objects, but probably more apt to pop up here.)
Copyright (c) 2001-2004 intes.net, inc.. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Chris Winters <chris@cwinters.com>
To install SPOPS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SPOPS
CPAN shell
perl -MCPAN -e shell install SPOPS
For more information on module installation, please visit the detailed CPAN module installation guide.