[ABE.pm] Coding for peace of mind

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Fri Aug 17 06:40:42 PDT 2007


* Ted Fiedler <fiedlert at gmail.com> [2007-08-17T08:06:33]
> my DB connections are pulled into being through the caiDB.pm Id just like to
> be able to name them
> in the ini file.

I'm not sure just what you want, so I'll guess.

Does this look useful:

  source = MySource
  target = MyTarget

  [MySource]
  dsn = dbi:SQLite:dbname=yourface.db

  [MyTarget]
  dsn = dbi:mysql:...
  username = ted
  password = secret
  AutoCommit = 1

$thinger->db('x') is:

  my %dbh;

  sub db {
    my ($self, $which) = @_;

    Carp::croak "no $which db registered" unless $Config->{_}{$which};

    return $dbh{ $which } if $dbh{ $which };

    my %db_param = %{ $Config->{_}{$which} };

    return $dbh{ $which } = DBI->connect(
      delete $db_param{ dsn },
      delete $db_param{ username },
      delete $db_param{ password },
      \%db_param,
    );
  }


-- 
rjbs


More information about the ABE-pm mailing list