NAME
My::DiscoverField - Sample rule for SPOPS::ClassFactory implementing autofield discovery
SYNOPSIS
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
DESCRIPTION
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.
GOTCHAS
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
Copyright (c) 2001-2002 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.
AUTHORS
Chris Winters <chris@cwinters.com>