Try this:
Subclass Class::DBI, adding 2 methods: one that knows how to find out who is using the program (using %ENV?) and one that knows how to generate login credentials as needed. Then use that to call setdb with the right username and password. You might also add triggers that would create an exception if a 'public' user tried to alter the DB.
Then subclass this intermediate class for each table.
Something like:
This is a common pattern with Class::DBI.package MyDB; use base 'Class::DBI'; __PACKAGE__->set_db('Main', 'dbi:mysql:mydb', &db_login_credentials); sub db_login_credentials { my $group = &who_is_this; if ($group eq 'staff') { return ('staff', 'password'); } elsif ($group eq 'public') { return ('public', 'password'); } else { die 'who is this person?'; } } sub who_is_this { # do whatever it takles to figure out if it's public or # staff, and return either 'staff' or 'public'; } if (&who_is_this eq 'public') { __PACKAGE__->add_trigger(before_create => sub { die 'not authorized to create'; }); __PACKAGE__->add_trigger(before_update => sub { die 'not authorized to update'; }); __PACKAGE__->add_trigger(before_delete => sub { die 'not authorized to delete'; }); }
In reply to Re: Different Database Permissions Using Class::DBI
by cleverett
in thread Different Database Permissions Using Class::DBI
by Wally Hartshorn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |