DBIx-Wrapper-Config-0.01000755 001751 000000 00000000000 10367246300 014675 5ustar00donwheel000000 000000 DBIx-Wrapper-Config-0.01/META.yml000644 001751 000000 00000000614 10367246277 016243 0ustar00donwheel000000 000000 # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: DBIx-Wrapper-Config version: 0.01 version_from: lib/DBIx/Wrapper/Config.pm installdirs: site requires: DBIx::Wrapper: 0 XML::Parser::Wrapper: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 DBIx-Wrapper-Config-0.01/t000755 001751 000000 00000000000 10367246300 015140 5ustar00donwheel000000 000000 DBIx-Wrapper-Config-0.01/t/00use.t000755 001751 000000 00000000303 10351415323 016333 0ustar00donwheel000000 000000 #!/usr/bin/env perl # Creation date: 2005-10-23 19:42:34 # Authors: don use strict; # main { use Test; BEGIN { plan tests => 1 } use DBIx::Wrapper::Config; ok(1); } exit 0; DBIx-Wrapper-Config-0.01/lib000755 001751 000000 00000000000 10367246300 015443 5ustar00donwheel000000 000000 DBIx-Wrapper-Config-0.01/lib/DBIx000755 001751 000000 00000000000 10367246300 016231 5ustar00donwheel000000 000000 DBIx-Wrapper-Config-0.01/lib/DBIx/Wrapper000755 001751 000000 00000000000 10367246300 017651 5ustar00donwheel000000 000000 DBIx-Wrapper-Config-0.01/lib/DBIx/Wrapper/Config.pm000644 001751 000000 00000013022 10367246024 021474 0ustar00donwheel000000 000000 # Creation date: 2005-10-23 19:43:33 # Authors: don # # Copyright (c) 2005 Don Owens . All rights reserved. # This is free software; you can redistribute it and/or modify it # under the same terms as Perl itself. See perlartistic. # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. =pod =head1 NAME DBIx::Wrapper::Config - Config Module for DBIx::Wrapper =head1 SYNOPSIS use DBIx::Wrapper::Config; my $dbh = DBIx::Wrapper::Config->connect($db_key, $conf_path, \%dbix_wrapper_attrs); =head1 DESCRIPTION This module allows you to create a configuration file in XML specifying information required to connect to databases using DBIx::Wrapper. This way you can keep your database connection specifications in one place. Each "db" element specifies a key/name for the database connection, which should be passed as the $db_key argument to connect() in order to connect to that database. The "db" element's children specify the dsn, authentication, and attribute information. dbi:mysql:database=test_db;host=example.com;port=3306 test_user test_pwd test_user test_pwd =cut use strict; use warnings; use 5.006_00; package DBIx::Wrapper::Config; our $VERSION = '0.01'; use DBIx::Wrapper; use XML::Parser::Wrapper; sub new { my $proto = shift; return $proto->connect(@_); } =pod =head2 connect($db_key, $conf_path, \%dbix_wrapper_attrs) Return a DBIx::Wrapper object connected to the database specified by $db_key in the file at $conf_path. %dbix_wrapper_attrs is the optional 5th argument to DBIx::Wrapper's connect() method, specifying handlers, etc. The file specified by $conf_path should be in the format specified in the DESCRIPTION section of this document. =cut sub connect { my $self = shift; my $db_key = shift; my $conf_path = shift; my $wrapper_attrs = shift; return unless $db_key; my $conf = $self->_read_conf($conf_path); unless ($conf and %$conf) { die "\n\nread conf failed"; return; } my $conf_entry = $conf->{$db_key}; unless ($conf_entry) { die "no conf entry"; } return DBIx::Wrapper->connect($conf_entry->{dsn}, $conf_entry->{user}, $conf_entry->{password}, $conf_entry->{attributes}, $wrapper_attrs); } sub _read_conf { my $self = shift; my $conf_path = shift; unless (defined($conf_path) and $conf_path ne '') { $conf_path = '/etc/dbix.conf.xml'; } return unless -r $conf_path; my $root = XML::Parser::Wrapper->new({ file => $conf_path }); unless ($root->name eq 'config') { # bad format return; } my $dbs = {}; my $db_tags = $root->kids('db'); return unless $db_tags and @$db_tags; foreach my $db_element (@$db_tags) { my $name = $db_element->attr('name'); next unless defined $name; my $dsn_element = $db_element->kid('dsn'); next unless $dsn_element; my $dsn; my $dsn_attrs = $dsn_element->attrs; if ($dsn_attrs and %$dsn_attrs) { $dsn = map { ($_ => $dsn_attrs->{$_}) } keys %$dsn_attrs; } else { $dsn = $dsn_element->text; } my $this_db = { dsn => $dsn }; $dbs->{$name} = $this_db; $this_db->{user} = $db_element->kid('user')->text; $this_db->{password} = $db_element->kid('password')->text; my $attributes = {}; $this_db->{attributes} = $attributes; my $attribute_list = $db_element->kids('attribute'); if ($attribute_list and @$attribute_list) { foreach my $attribute_element (@$attribute_list) { $attributes->{$attribute_element->attr('name')} = $attribute_element->attr('value'); } } } return $dbs; } =pod =head1 EXAMPLES =head1 DEPENDENCIES DBIx::Wrapper, XML::Parser::Wrapper =head1 AUTHOR Don Owens =head1 LICENSE AND COPYRIGHT Copyright (c) 2005 Don Owens . All rights reserved. This is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =head1 SEE ALSO DBIx::Wrapper, DBI =head1 VERSION 0.01 =cut 1; # Local Variables: # # mode: perl # # tab-width: 4 # # indent-tabs-mode: nil # # cperl-indent-level: 4 # # perl-indent-level: 4 # # End: # # vim:set ai si et sta ts=4 sw=4 sts=4: DBIx-Wrapper-Config-0.01/MANIFEST000644 001751 000000 00000000241 10351422661 016101 0ustar00donwheel000000 000000 MANIFEST INSTALL README WhatsNew Makefile.PL lib/DBIx/Wrapper/Config.pm t/00use.t META.yml Module meta-data (added by MakeMaker) DBIx-Wrapper-Config-0.01/WhatsNew000644 001751 000000 00000000040 10327045177 016436 0ustar00donwheel000000 000000 Version 0.01 * Initial release DBIx-Wrapper-Config-0.01/INSTALL000644 001751 000000 00000000255 10327045177 016014 0ustar00donwheel000000 000000 Copyright (c) 2003-2005 Don Owens See the COPYRIGHT section in Config.pm for usage and distribution rights. INSTALLATION perl Makefile.PL make make test make install DBIx-Wrapper-Config-0.01/README000644 001751 000000 00000005262 10367246273 015652 0ustar00donwheel000000 000000 NAME DBIx::Wrapper::Config - Config Module for DBIx::Wrapper SYNOPSIS use DBIx::Wrapper::Config; my $dbh = DBIx::Wrapper::Config->connect($db_key, $conf_path, \%dbix_wrapper_attrs); DESCRIPTION This module allows you to create a configuration file in XML specifying information required to connect to databases using DBIx::Wrapper. This way you can keep your database connection specifications in one place. Each "db" element specifies a key/name for the database connection, which should be passed as the $db_key argument to connect() in order to connect to that database. The "db" element's children specify the dsn, authentication, and attribute information. dbi:mysql:database=test_db;host=example.com;port=3306 test_user test_pwd test_user test_pwd connect($db_key, $conf_path, \%dbix_wrapper_attrs) Return a DBIx::Wrapper object connected to the database specified by $db_key in the file at $conf_path. %dbix_wrapper_attrs is the optional 5th argument to DBIx::Wrapper's connect() method, specifying handlers, etc. The file specified by $conf_path should be in the format specified in the DESCRIPTION section of this document. EXAMPLES DEPENDENCIES DBIx::Wrapper, XML::Parser::Wrapper AUTHOR Don Owens LICENSE AND COPYRIGHT Copyright (c) 2005 Don Owens . All rights reserved. This is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. SEE ALSO DBIx::Wrapper, DBI VERSION 0.01 DBIx-Wrapper-Config-0.01/Makefile.PL000755 001751 000000 00000001774 10351420716 016740 0ustar00donwheel000000 000000 #!/usr/bin/env perl # Creation date: 2005-10-23 19:38:19 # Authors: don use strict; use warnings; use Carp; # main { use ExtUtils::MakeMaker; WriteMakefile( NAME => 'DBIx::Wrapper::Config', DISTNAME => 'DBIx-Wrapper-Config', VERSION_FROM => 'lib/DBIx/Wrapper/Config.pm', ABSTRACT => 'Config Module for DBIx::Wrapper', AUTHOR => 'DON OWENS ', PM => { 'lib/DBIx/Wrapper/Config.pm' => '$(INST_LIBDIR)/Config.pm', }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' }, DIR => [], EXE_FILES => [], PREREQ_PM => { 'DBIx::Wrapper' => 0, 'XML::Parser::Wrapper' => 0, }, ); } exit 0; ############################################################################### # Subroutines