Skip to content

Commit f711d92

Browse files
author
Buddy Burden
committed
=> new function derive() to produce a DataStore from an existing $dbh
moving away from Barefoot.pm to Debuggit.pm
1 parent ebe8be5 commit f711d92

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Barefoot/DataStore.pm

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use warnings;
2929
use version;
3030
our $VERSION = qv('2.0.1');
3131

32+
use Debuggit;
33+
#local $Debuggit::formatter = sub { return (caller(2))[3] . ':bmoogle: ' . Debuggit::default_formatter(@_) };
34+
3235
use DBI;
3336
use Carp;
3437
use Storable;
@@ -65,7 +68,7 @@ my $QUERY_SUB = qr/^\{.+\}$/;
6568

6669

6770
our $data_store_dir = DEBUG ? "." : "/etc/data_store";
68-
#our $data_store_dir = "/etc/data_store";
71+
debuggit(4 => 'DataStore load: data store dir set to', $data_store_dir);
6972

7073
our $base_types =
7174
{
@@ -542,7 +545,7 @@ sub _transform_query
542545
# now put the quoted strings back (note that it's okay to have a _variable_ inside a quoted string, so we
543546
# don't do anything in particular to avoid those)
544547
$query =~ s/{Q(\d+)}/${$quoted_strings[$1]}/g;
545-
548+
546549
# sort out parameters according to whether they're the query (first param), hash or array placeholder
547550
# (a.k.a. "non-scalar placeholder") values (any hashrefs or arrayrefs), or variables (everything else)
548551
my (@ns_placeholders, @var_stuff);
@@ -872,7 +875,7 @@ sub create
872875

873876
# RDBMS has to be present
874877
croak("must specify RDBMS to data store") unless exists $attribs{'rdbms'};
875-
878+
876879
# user has to be present, and should be moved out of config section
877880
croak("must specify user to data store") unless exists $attribs{'user'};
878881
$this->{'user'} = $attribs{'user'};
@@ -895,6 +898,22 @@ sub create
895898
}
896899

897900

901+
sub derive
902+
{
903+
my $class = shift;
904+
my ($dbh, %attribs) = @_;
905+
906+
# RDBMS has to be present
907+
croak("must specify RDBMS to data store") unless exists $attribs{'rdbms'};
908+
909+
my $this = {};
910+
$this->{'dbh'} = $dbh;
911+
912+
bless $this, $class;
913+
return $this;
914+
}
915+
916+
898917
sub DESTROY
899918
{
900919
my $this = shift;
@@ -1130,6 +1149,7 @@ sub replace_table
11301149
sub create_table
11311150
{
11321151
my ($this, $table_name, $columns, $opts) = @_;
1152+
debuggit(4 => 'DataStore::create_table: table', $table_name, 'columns', DUMP => $columns, 'opts', DUMP => $opts);
11331153
$opts ||= {};
11341154
$opts->{'DATADICT'} ||= '';
11351155

0 commit comments

Comments
 (0)