| 1 | package DBIx::DBH::Legacy; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | use DBI; | ||
| 9 | use Params::Validate qw( :all ); | ||
| 10 | |||
| 11 | our $VERSION = '0.2'; | ||
| 12 | |||
| 13 | our @attr = qw | ||
| 14 | ( | ||
| 15 | dbi_connect_method | ||
| 16 | Warn | ||
| 17 | |||
| 18 | _Active | ||
| 19 | _Executed | ||
| 20 | _Kids | ||
| 21 | _ActiveKids | ||
| 22 | _CachedKids | ||
| 23 | _CompatMode | ||
| 24 | |||
| 25 | InactiveDestroy | ||
| 26 | PrintWarn | ||
| 27 | PrintError | ||
| 28 | RaiseError | ||
| 29 | HandleError | ||
| 30 | HandleSetErr | ||
| 31 | |||
| 32 | _ErrCount | ||
| 33 | |||
| 34 | ShowErrorStatement | ||
| 35 | TraceLevel | ||
| 36 | FetchHashKeyName | ||
| 37 | ChopBlanks | ||
| 38 | LongReadLen | ||
| 39 | LongTruncOk | ||
| 40 | TaintIn | ||
| 41 | TaintOut | ||
| 42 | Taint | ||
| 43 | Profile | ||
| 44 | _should-add-support-for-private_your_module_name_* | ||
| 45 | |||
| 46 | |||
| 47 | AutoCommit | ||
| 48 | |||
| 49 | _Driver | ||
| 50 | _Name | ||
| 51 | _Statement | ||
| 52 | |||
| 53 | RowCacheSize | ||
| 54 | |||
| 55 | _Username | ||
| 56 | ); | ||
| 57 | |||
| 58 | # Preloaded methods go here. | ||
| 59 | |||
| 60 | Params::Validate::validation_options(allow_extra => 1); | ||
| 61 | |||
| 62 | sub connect { | ||
| 63 | |||
| 64 | my @connect_data = connect_data(@_); | ||
| 65 | |||
| 66 | my $dbh; | ||
| 67 | eval | ||
| 68 | { | ||
| 69 | $dbh = DBI->connect( @connect_data ); | ||
| 70 | }; | ||
| 71 | |||
| 72 | die $@ if $@; | ||
| 73 | die 'Unable to connect to database' unless $dbh; | ||
| 74 | |||
| 75 | return $dbh; | ||
| 76 | |||
| 77 | } | ||
| 78 | |||
| 79 | sub dbi_attr { | ||
| 80 | my ($h, %p) = @_; | ||
| 81 | |||
| 82 | $h = {} unless defined $h; | ||
| 83 | |||
| 84 | for my $attr (@attr) { | ||
| 85 | if (exists $p{$attr}) { | ||
| 86 | # warn "$attr = $p{$attr};"; | ||
| 87 | $h->{$attr} = $p{$attr}; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | $h; | ||
| 92 | } | ||
| 93 | |||
| 94 | sub connect_data { | ||
| 95 | |||
| 96 | my $class = shift; | ||
| 97 | my %p = @_; | ||
| 98 | |||
| 99 | my $subclass = "DBIx::DBH::$p{driver}"; | ||
| 100 | eval "require $subclass"; | ||
| 101 | die "unable to require $subclass to support the $p{driver} driver.\n" if $@; | ||
| 102 | |||
| 103 | my ($dsn, $user, $pass, $attr) = $subclass->connect_data(@_); | ||
| 104 | $attr = dbi_attr($attr, %p); | ||
| 105 | |||
| 106 | ($dsn, $user, $pass, $attr) | ||
| 107 | |||
| 108 | } | ||
| 109 | |||
| 110 | sub form_dsn { | ||
| 111 | |||
| 112 | (connect_data(@_))[0]; | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | 1; | ||
| 118 | __END__ |