DBIx-Safe
view release on metacpan or search on metacpan
# -*-cperl-*-
#
# Copyright 2006-2007 Greg Sabino Mullane <greg@endpoint.com>
#
# DBIx::Safe is a safer way of handling database connections.
# You can specify exactly which commands can be run.
#
package DBIx::Safe;
use 5.008003;
use utf8;
use strict;
use warnings;
use IO::Handle;
use DBI 1.42;
{
our $VERSION = '1.2.5';
*STDOUT->autoflush(1);
*STDERR->autoflush(1);
my %inner;
sub TIEHASH {
my $class = shift;
my $arg = shift;
my $self = bless {}, $class;
$inner{$self} = $arg;
return $self;
}
sub STORE {
my ($self,$key,$value) = @_;
my $inner = $inner{$self};
my $origkey = $key;
$key = lc $key;
die "Invalid access\n" unless index $key, 'dbixsafe_';
if (exists $inner->{dbixsafe_allow_attribute}{$key}) {
$inner->{dbixsafe_allow_attribute}{$key}++;
$inner->{dbixsafe_sdbh}{$origkey} = $value;
return;
}
die qq{Cannot change attribute "$key"};
}
sub FETCH {
my ($self,$key) = @_;
my $inner = $inner{$self};
die "Invalid access\n" unless index $key, 'dbixsafe_';
## Assume it is a $dbh value, and return it
return $inner->{dbixsafe_sdbh}{$key};
}
sub FIRSTKEY {
my $self = shift;
=head3 allow_regex()
Specifies regular expressions which are allowed to run. Argument must be a regular expression,
or an arrayref of regular expressions. Returns the current list.
=head3 unallow_regex()
Same as allow_regex, but will remove regexes from the list.
=head3 deny_regex()
Specifies regular expressions which are NOT allowed to run. Arguments and return the same as allow_regex().
=head3 undeny regex()
Same as deny_regex, but will remove regexes from the list.
=head3 allow_attribute()
Specifies database handle attributes that are allowed to be changed. By default, nothing can be read.
Argument is a whitespace-separated list of words in a string, or an arrayref of such strings. Returns
the current list.
=head3 unallow_attribute()
Same as allow_attributes, but removes attributes from the list.
=head2 Testing
DBIx::Safe has a very comprehensive test suite, so please use it! The only thing you should need is a
database connection, by setting the environment variables DBI_DSN and DBI_USER (and DBI_PASS if needed).
You can optionally run the module through Perl::Critic by setting the TEST_AUTHOR environment variable.
You will need to have the modules Perl::Critic and Test::Perl::Critic installed.
Please report any test failures to the author or bucardo-general@bucardo.org.
=head2 Supported Databases
Due to the difficulty of ensuring safe access to the database, each type of database must be specifically
written into DBIx::Safe. Current databases supported are: Postgres (DBD::Pg).
=head1 WEBSITE
The latest version and other information about DBIx::Safe can be found at:
http://bucardo.org/dbix_safe/
=head1 DEVELOPMENT
The latest development version can be checked out by using git:
git clone http://bucardo.org/dbixsafe.git/
=head1 BUGS
Bugs should be reported to the author or bucardo-general@bucardo.org.
=head1 AUTHOR
Greg Sabino Mullane <greg@endpoint.com>
=head1 LICENSE AND COPYRIGHT
Copyright 2006-2007 Greg Sabino Mullane <greg@endpoint.com>.
This software is free to use: see the LICENSE file for details.
=cut
( run in 1.278 second using v1.01-cache-2.11-cpan-870870ed90f )