|
From: Chris W. <la...@us...> - 2001-10-12 04:09:02
|
Update of /cvsroot/openinteract/SPOPS/eg/My
In directory usw-pr-cvs1:/tmp/cvs-serv1808
Modified Files:
DiscoverField.pm
Log Message:
added more docs; use the SPOPS DEBUG constant
Index: DiscoverField.pm
===================================================================
RCS file: /cvsroot/openinteract/SPOPS/eg/My/DiscoverField.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DiscoverField.pm 2001/10/08 02:04:58 1.3
--- DiscoverField.pm 2001/10/12 04:08:59 1.4
***************
*** 1,13 ****
package My::DiscoverField;
use strict;
! use SPOPS qw( _w _wm );
use SPOPS::ClassFactory qw( ERROR OK NOTIFY );
- use constant DEBUG => 1;
-
sub behavior_factory {
my ( $class ) = @_;
! DEBUG() && _wm( 1, DEBUG, "Installing field discovery for ($class)" );
return { manipulate_configuration => \&discover_fields };
}
--- 1,13 ----
package My::DiscoverField;
+ # $Id$
+
use strict;
! use SPOPS qw( DEBUG _w );
use SPOPS::ClassFactory qw( ERROR OK NOTIFY );
sub behavior_factory {
my ( $class ) = @_;
! DEBUG() && _w( 1, "Installing field discovery for ($class)" );
return { manipulate_configuration => \&discover_fields };
}
***************
*** 30,35 ****
return ( NOTIFY, "Cannot discover fields: $@" ) if ( $@ );
$CONFIG->{field} = $sth->{NAME};
! DEBUG() && _wm( 1, DEBUG, "Table: ($CONFIG->{base_table}); ",
! "Fields: (", join( ', ', @{ $CONFIG->{field} } ), ")" );
return ( OK, undef );
}
--- 30,35 ----
return ( NOTIFY, "Cannot discover fields: $@" ) if ( $@ );
$CONFIG->{field} = $sth->{NAME};
! DEBUG() && _w( 1, "Table: ($CONFIG->{base_table}); ",
! "Fields: (", join( ', ', @{ $CONFIG->{field} } ), ")" );
return ( OK, undef );
}
***************
*** 59,62 ****
--- 59,89 ----
# All fields in 'mydata' table now available as object properties
+
+ =head1 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.
+
+ =head1 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
+ L<SPOPS::DBI|SPOPS::DBI> objects, but probably more apt to pop up
+ here.)
=head1 COPYRIGHT
|