blib000755 001751 000000 00000000000 10351415300 011611 5ustar00donwheel000000 000000 blib/lib000755 001751 000000 00000000000 10351415276 012373 5ustar00donwheel000000 000000 blib/lib/DBIx000755 001751 000000 00000000000 10351415275 013160 5ustar00donwheel000000 000000 blib/lib/DBIx/Wrapper000755 001751 000000 00000000000 10367246241 014602 5ustar00donwheel000000 000000 blib/lib/DBIx/Wrapper/.exists000644 001751 000000 00000000000 10224067271 016163 0ustar00donwheel000000 000000 blib/lib/DBIx/Wrapper/Config.pm000444 001751 000000 00000013022 10367246024 016417 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: blib/lib/auto000755 001751 000000 00000000000 10351415277 013344 5ustar00donwheel000000 000000 blib/lib/auto/DBIx000755 001751 000000 00000000000 10351415277 014132 5ustar00donwheel000000 000000 blib/lib/auto/DBIx/Wrapper000755 001751 000000 00000000000 10351415277 015552 5ustar00donwheel000000 000000 blib/lib/auto/DBIx/Wrapper/Config000755 001751 000000 00000000000 10351415277 016757 5ustar00donwheel000000 000000 blib/lib/auto/DBIx/Wrapper/Config/.exists000644 001751 000000 00000000000 10224067271 020340 0ustar00donwheel000000 000000 blib/arch000755 001751 000000 00000000000 10351415276 012542 5ustar00donwheel000000 000000 blib/arch/auto000755 001751 000000 00000000000 10351415276 013512 5ustar00donwheel000000 000000 blib/arch/auto/DBIx000755 001751 000000 00000000000 10351415276 014300 5ustar00donwheel000000 000000 blib/arch/auto/DBIx/Wrapper000755 001751 000000 00000000000 10351415276 015720 5ustar00donwheel000000 000000 blib/arch/auto/DBIx/Wrapper/Config000755 001751 000000 00000000000 10351415277 017126 5ustar00donwheel000000 000000 blib/arch/auto/DBIx/Wrapper/Config/.exists000644 001751 000000 00000000000 10224067271 020507 0ustar00donwheel000000 000000