My 'read-only' objects now have their very own metadata class. Trying to update from the 'save', 'insert', 'update', etc. now fails. I also have the accessors throwing Exception::Class objects if someone tries to set an attribute value. However, it's a nasty hack because the other code examples I saw here were failing:
sub add_columns { my ( $self, @columns ) = @_; $self->SUPER::add_columns(@columns); my $class = $self->class; foreach my $column ( $self->columns ) { $column->add_trigger( event => 'on_set', code => sub { my ($called_from) = caller(1); my $attribute = $class->_attribute_name($column); return if $called_from eq 'Rose::Object'; throw_read_only "Attribute '$attribute' is read-only"; }, ); } } (I don't rely on the return value of $self->SUPER::add_columns(@columns) because we're only using the CPAN version) Note the 'return' condition. I found that if I didn't have that in, the following would throw an exception: my $os = Donhost::OS->new( os => 'ubuntu' ); The hack guarantees that only things like the following throwing exceptions: $os->os('windows'); $os->description('sucks'); The hack relies on the order of call stack frames being different when I'm constructing an object or just setting an accessor directly. How can I do this without relying on the internals like this? Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/ ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object