r75945 - in /branches/upstream/libcgi-application-plugin-dbh-perl: ./ current/ current/lib/ current/lib/CGI/ current/lib/CGI/Application/ current/lib/CGI/Application/Plugin/ current/t/
periapt-guest at users.alioth.debian.org
periapt-guest at users.alioth.debian.org
Sat Jun 18 12:25:51 UTC 2011
Author: periapt-guest
Date: Sat Jun 18 12:25:49 2011
New Revision: 75945
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75945
Log:
[svn-inject] Installing original source of libcgi-application-plugin-dbh-perl (4.00)
Added:
branches/upstream/libcgi-application-plugin-dbh-perl/
branches/upstream/libcgi-application-plugin-dbh-perl/current/
branches/upstream/libcgi-application-plugin-dbh-perl/current/Build.PL
branches/upstream/libcgi-application-plugin-dbh-perl/current/Changes
branches/upstream/libcgi-application-plugin-dbh-perl/current/MANIFEST
branches/upstream/libcgi-application-plugin-dbh-perl/current/META.yml
branches/upstream/libcgi-application-plugin-dbh-perl/current/Makefile.PL
branches/upstream/libcgi-application-plugin-dbh-perl/current/README
branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/
branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/
branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/
branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/
branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/DBH.pm
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppAutoConfig.pm
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppBasic.pm
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppExistingDBH.pm
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppMultiHandle.pm
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/auto_config.t
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/basic.t
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/existing_dbh.t
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/multi_handle.t
branches/upstream/libcgi-application-plugin-dbh-perl/current/t/pod.t
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/Build.PL?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/Build.PL (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/Build.PL Sat Jun 18 12:25:49 2011
@@ -1,0 +1,16 @@
+use Module::Build;
+
+Module::Build->new(
+ module_name => 'CGI::Application::Plugin::DBH',
+ license => 'perl',
+ requires => {
+ 'CGI::Application' => 0,
+ 'DBI' => 0,
+ 'DBD::Mock' => .11,
+ },
+ create_makefile_pl => 'traditional',
+ create_readme => 1,
+ dist_author => 'Mark Stosberg <mark at summersault.com>',
+ dist_abstract => 'Plugin that adds DBH support to CGI::Application',
+)->create_build_script;
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/Changes?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/Changes (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/Changes Sat Jun 18 12:25:49 2011
@@ -1,0 +1,24 @@
+Revision history for Perl extension CGI::Application::Plugin::DBH
+
+4.00 Thu Nov 3 16:59:28 EST 2005
+ - Added support for configuring through a callback. This can be used to
+ create a connection on your own, and still have it be lazy loaded.
+ This was requested for use with connect_cached().
+
+3.00 Thu Mar 17 20:07:32 EST 2005
+ - Added support for auto-configuring the handle through the instance
+ script or environment variables. (Thilo Planz).
+
+2.00 Wed Oct 6 21:21:55 EST 2004
+ - Added support for multiple handles and named handles. The API is
+ completely backwards compatible with the existing behavior. (Tony Fraser)
+
+1.00 Wed Sep 8 19:15:44 EST 2004
+ - Bumped version for release to CPAN
+
+0.02 Sun Sep 5 12:05:50 EST 2004
+ - Added support for initializing with an existing database handle.
+
+0.01 Sat Sep 4 21:54:31 EST 2004
+ - initial release
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/MANIFEST?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/MANIFEST (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/MANIFEST Sat Jun 18 12:25:49 2011
@@ -1,0 +1,16 @@
+Build.PL
+Changes
+lib/CGI/Application/Plugin/DBH.pm
+Makefile.PL
+MANIFEST
+META.yml
+README
+t/basic.t
+t/existing_dbh.t
+t/multi_handle.t
+t/pod.t
+t/TestAppBasic.pm
+t/TestAppExistingDBH.pm
+t/TestAppMultiHandle.pm
+t/TestAppAutoConfig.pm
+t/auto_config.t
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/META.yml?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/META.yml (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/META.yml Sat Jun 18 12:25:49 2011
@@ -1,0 +1,16 @@
+--- #YAML:1.0
+name: CGI-Application-Plugin-DBH
+version: 4.00
+author:
+ - Mark Stosberg <mark at summersault.com>
+abstract: Plugin that adds DBH support to CGI::Application
+license: perl
+requires:
+ CGI::Application: 0
+ DBD::Mock: 0.11
+ DBI: 0
+provides:
+ CGI::Application::Plugin::DBH:
+ file: lib/CGI/Application/Plugin/DBH.pm
+ version: 4.00
+generated_by: Module::Build version 0.2611
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/Makefile.PL?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/Makefile.PL (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/Makefile.PL Sat Jun 18 12:25:49 2011
@@ -1,0 +1,15 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
+use ExtUtils::MakeMaker;
+WriteMakefile
+(
+ 'NAME' => 'CGI::Application::Plugin::DBH',
+ 'VERSION_FROM' => 'lib/CGI/Application/Plugin/DBH.pm',
+ 'PREREQ_PM' => {
+ 'CGI::Application' => '0',
+ 'DBD::Mock' => '0.11',
+ 'DBI' => '0'
+ },
+ 'INSTALLDIRS' => 'site',
+ 'PL_FILES' => {}
+ )
+;
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/README?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/README (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/README Sat Jun 18 12:25:49 2011
@@ -1,0 +1,175 @@
+NAME
+ CGI::Application::Plugin::DBH - Easy DBI access from CGI::Application
+
+SYNOPSIS
+ use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
+
+ sub cgiapp_init {
+ my $self = shift;
+
+ # use the same args as DBI->connect();
+ $self->dbh_config($data_source, $username, $auth, \%attr);
+
+ # or to use more than one dbh
+ $self->dbh_config('my_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ $self->dbh_config('my_other_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ }
+
+ sub my_run_mode {
+ my $self = shift;
+
+ my $date = $self->dbh->selectrow_array("SELECT CURRENT_DATE");
+ # again with a named handle
+ $date = $self->dbh('my_handle')->selectrow_array("SELECT CURRENT_DATE");
+
+ # OR ...
+
+ my $dbh = $self->dbh;
+ # again with a named handle
+ $dbh = $self->dbh('my_other_handle');
+ my $date = $dbh->selectrow_array("SELECT CURRENT_DATE");
+ }
+
+DESCRIPTION
+ CGI::Application::Plugin::DBH adds easy access to a DBI database handle
+ to your CGI::Application modules. Lazy loading is used to prevent a
+ database connection from being made if the "dbh" method is not called
+ during the request. In other words, the database connection is not
+ created until it is actually needed.
+
+METHODS
+ dbh()
+ my $date = $self->dbh->selectrow_array("SELECT CURRENT_DATE");
+ # again with a named handle
+ $date = $self->dbh('my_handle')->selectrow_array("SELECT CURRENT_DATE");
+
+ # OR ...
+
+ my $dbh = $self->dbh;
+ # again with a named handle
+ $dbh = $self->dbh('my_other_handle');
+ my $date = $dbh->selectrow_array("SELECT CURRENT_DATE");
+
+ This method will return the current DBI database handle. The database
+ handle is created on the first call to this method, and any subsequent
+ calls will return the same handle.
+
+ dbh_config()
+ sub cgiapp_init {
+ my $self = shift;
+
+ # use the same args as DBI->connect();
+ $self->dbh_config($data_source, $username, $auth, \%attr);
+
+ # or to use more than one dbh
+ $self->dbh_config('my_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ $self->dbh_config('my_other_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+
+ # ...or use some existing handle you have
+ $self->dbh_config($DBH);
+ $self->dbh_config('my_handle', $DBH); # this works too
+
+ # Use a callback to create your owh handle that is still lazy loaded
+ $self->dbh_config(sub { DBI->connect_cached(); });
+ }
+
+ Used to provide your DBI connection parameters. You can either pass in
+ an existing DBI database handle, or provide the usual parameters used
+ for DBI->connect().
+
+ The recommended place to call "dbh_config" is in the "cgiapp_init" stage
+ of CGI::Application. If this method is called after the database handle
+ has already been accessed, then it will die with an error message.
+
+ Automatic configuration using CGI::App instance parameters
+ An alternative to explicitly calling "dbh_config" in your application is
+ to rely on the presence of specific instance parameters that allow the
+ plugin to configure itself.
+
+ If you set the CGI::App parameter "::Plugin::DBH::dbh_config" to an
+ array reference the contents of that array will be used as parameters to
+ "dbh_config" (if it has not been explicitly called before).
+
+ The code in the synopsis can be rewritten as
+
+ use CGI::Application::Plugin::DBH (qw/dbh/);
+ # no longer a need to import dbh_config
+
+ sub cgiapp_init {
+ # you do not need to do anything here
+ }
+
+ sub my_run_mode {
+
+ # this part stays unchanged
+
+ ....
+
+ }
+
+ and in the instance script ( or instance configuration file, if you
+ have)
+
+ $app->param('::Plugin::DBH::dbh_config' =>
+ [ $data_source, $username, $auth, \%attr ] );
+
+ If you want to configure more than one handle, set up a hash with the
+ handle names as keys:
+
+ $app->param('::Plugin::DBH::dbh_config' =>
+ { my_handle => [ $data_source, $username, $auth, \%attr ] ,
+ my_other_handle => [ $data_source, $username, $auth, \%attr ]
+ } );
+
+ Automatic configuration with DBI environment variables
+ If you do not set any parameters, and do not call "dbh_config", this
+ plugin checks to see if you set the DBI environment variable "DBI_DSN".
+ If present, this DSN will be used for the default handle. Note that the
+ DBI documentation does not encourage using this method (especially in
+ the context of web applications), that you will most likely have to also
+ set "DBI_USER" and "DBI_PASS", and that this can only be used for the
+ default handle.
+
+ dbh_default_name()
+ sub my_runmode {
+ my $self = shift;
+
+ my $old_handle_name = $self->dbh_default_name('my_handle');
+ $self->some_legacy_code(); # some_legacy_code() will get "my_handle"
+ # when it calls $self->dbh() without parameters
+
+ $self->dbh_default_name($old_handle_name); # Return to normal.
+ }
+
+ Can be used to alter the name of the handle that is returned by dbh()
+ when called with no parameters. It can even be used to alter the name
+ used for the unamed handle if called before dbh_config().
+
+ Using this method is completely optional. If you don't have a use for it
+ don't use it. Internally the handle name "__cgi_application_plugin_dbh"
+ is used to keep track of the unnamed handle unless it is changed by
+ dbh_default_name() before a call to dbh_config() without a name
+ parameter.
+
+SEE ALSO
+ Ima::DBI is similar, but has much more complexity and features.
+
+ CGI::Application, DBI, CGI::Application::Plugin::ValidateRM, perl(1)
+
+AUTHOR
+ Mark Stosberg <mark at summersault.com>
+
+ Multi Handle Support added by: Tony Fraser <tony at sybaspace.com>
+
+ Autoconfig Support added by: Thilo Planz <thilo at cpan.org>
+
+LICENSE
+ Copyright (C) 2004 Mark Stosberg <mark at summersault.com>
+
+ This library is free software. You can modify and or distribute it under
+ the same terms as Perl itself.
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/DBH.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/DBH.pm?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/DBH.pm (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/lib/CGI/Application/Plugin/DBH.pm Sat Jun 18 12:25:49 2011
@@ -1,0 +1,316 @@
+package CGI::Application::Plugin::DBH;
+
+
+use strict;
+use vars qw($VERSION @ISA @EXPORT_OK);
+use Carp;
+require Exporter;
+ at ISA = qw(Exporter);
+# Items to export into callers namespace by default. Note: do not export
+# names by default without a very good reason. Use EXPORT_OK instead.
+# Do not simply export all your public functions/methods/constants.
+ at EXPORT_OK = qw(
+ dbh
+ dbh_config
+ dbh_default_name
+);
+
+$VERSION = '4.00';
+
+sub dbh {
+ my $self = shift;
+ my $name = shift;
+
+ $self->{__DBH_DEFAULT_NAME} ||= "__cgi_application_plugin_dbh"; # First use case.
+ $name ||= $self->{__DBH_DEFAULT_NAME}; # Unamed handle case.
+
+ unless ($self->{__DBH_CONFIG}{$name}){
+ __auto_config($self, $name);
+ croak "must call dbh_config() before calling dbh()." unless $self->{__DBH_CONFIG}{$name};
+ }
+
+ unless( defined($self->{__DBH}{$name}) && $self->{__DBH}{$name}->ping ) {
+ # create DBH object
+ if(my $config = $self->{__DBH_CONFIG}{$name} ) {
+ # Use a callback
+ if (ref $config eq 'CODE') {
+ $self->{__DBH}{$name} = $config->();
+ }
+ # use the parameters the user supplied
+ else {
+ require DBI;
+ $self->{__DBH}{$name} = DBI->connect(@{ $self->{__DBH_CONFIG}{$name} });
+ }
+ } else {
+ }
+ }
+
+ return $self->{__DBH}{$name};
+}
+
+sub dbh_config {
+ my $self = shift;
+
+ $self->{__DBH_DEFAULT_NAME} ||= "__cgi_application_plugin_dbh"; # First use case.
+
+ my $name = shift if( ref($_[1]) );
+ $name ||= $self->{__DBH_DEFAULT_NAME}; # Unamed handle case.
+
+ croak "Calling dbh_config after the dbh has already been created" if( defined $self->{__DBH}{$name} );
+
+ # See if a handle is being passed in directly.
+ require UNIVERSAL;
+ if( ref($_[0]) eq 'ARRAY' or ref $_[0] eq 'CODE' ) {
+ $self->{__DBH_CONFIG}{$name} = shift;
+ }
+ elsif( ref($_[0]) and $_[0]->isa('DBI::db') ) {
+ $self->{__DBH}{$name} = shift;
+
+ # Set this to note that we have completed the 'config' stage.
+ $self->{__DBH_CONFIG}{$name} = 1;
+ }
+ else {
+ $self->{__DBH_CONFIG}{$name} = \@_;
+ }
+
+}
+
+sub __auto_config {
+ # get parameters for dbh_config from CGI::App instance parameters
+ my $app = shift;
+ my $name = shift;
+
+
+ my $params = $app->param('::Plugin::DBH::dbh_config');
+ return __auto_config_env($app, $name) unless $params;
+
+ # if array reference: only one handle configured, pass array contents to dbh_config
+ if (UNIVERSAL::isa($params, 'ARRAY')){
+ # verify that we really want the default handle
+ return unless $name eq dbh_default_name($app);
+ dbh_config($app, @$params);
+ return;
+ }
+
+ # if hash reference: many handles configured, named with the hash keys
+ if (UNIVERSAL::isa($params, 'HASH')){
+ $params = $params->{$name};
+ return __auto_config_env($app, $name) unless $params;
+ dbh_config($app, $name, $params);
+ return;
+ }
+
+ croak "Parameter ::Plugin::DBH::dbh_config must be an array or hash reference";
+}
+
+sub __auto_config_env{
+ # check if DBI environment variable is set
+ # this can be used to configure the default handle
+ my $app = shift;
+ my $name = shift;
+
+ return unless $name eq dbh_default_name($app);
+ return unless $ENV{DBI_DSN};
+ # DBI_DSN is set, so autoconfigure with all DSN, user id, pass all undefined
+ dbh_config($app, undef, undef, undef);
+}
+
+sub dbh_default_name {
+ my $self = shift;
+ my $old_name = $self->{__DBH_DEFAULT_NAME} || "__cgi_application_plugin_dbh"; # Possible first use case.
+ $self->{__DBH_DEFAULT_NAME} = shift if $_[0];
+ return $old_name;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+CGI::Application::Plugin::DBH - Easy DBI access from CGI::Application
+
+=head1 SYNOPSIS
+
+ use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
+
+ sub cgiapp_init {
+ my $self = shift;
+
+ # use the same args as DBI->connect();
+ $self->dbh_config($data_source, $username, $auth, \%attr);
+
+ # or to use more than one dbh
+ $self->dbh_config('my_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ $self->dbh_config('my_other_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ }
+
+ sub my_run_mode {
+ my $self = shift;
+
+ my $date = $self->dbh->selectrow_array("SELECT CURRENT_DATE");
+ # again with a named handle
+ $date = $self->dbh('my_handle')->selectrow_array("SELECT CURRENT_DATE");
+
+ # OR ...
+
+ my $dbh = $self->dbh;
+ # again with a named handle
+ $dbh = $self->dbh('my_other_handle');
+ my $date = $dbh->selectrow_array("SELECT CURRENT_DATE");
+ }
+
+
+=head1 DESCRIPTION
+
+CGI::Application::Plugin::DBH adds easy access to a L<DBI|DBI> database handle to
+your L<CGI::Application|CGI::Application> modules. Lazy loading is used to prevent a database
+connection from being made if the C<dbh> method is not called during the
+request. In other words, the database connection is not created until it is
+actually needed.
+
+=head1 METHODS
+
+=head2 dbh()
+
+ my $date = $self->dbh->selectrow_array("SELECT CURRENT_DATE");
+ # again with a named handle
+ $date = $self->dbh('my_handle')->selectrow_array("SELECT CURRENT_DATE");
+
+ # OR ...
+
+ my $dbh = $self->dbh;
+ # again with a named handle
+ $dbh = $self->dbh('my_other_handle');
+ my $date = $dbh->selectrow_array("SELECT CURRENT_DATE");
+
+This method will return the current L<DBI|DBI> database handle. The database handle is created on
+the first call to this method, and any subsequent calls will return the same handle.
+
+=head2 dbh_config()
+
+ sub cgiapp_init {
+ my $self = shift;
+
+ # use the same args as DBI->connect();
+ $self->dbh_config($data_source, $username, $auth, \%attr);
+
+ # or to use more than one dbh
+ $self->dbh_config('my_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+ $self->dbh_config('my_other_handle',
+ [ $data_source, $user, $auth, \%attr ]);
+
+ # ...or use some existing handle you have
+ $self->dbh_config($DBH);
+ $self->dbh_config('my_handle', $DBH); # this works too
+
+ # Use a callback to create your owh handle that is still lazy loaded
+ $self->dbh_config(sub { DBI->connect_cached(); });
+ }
+
+Used to provide your DBI connection parameters. You can either pass in an existing
+DBI database handle, or provide the usual parameters used for DBI->connect().
+
+The recommended place to call C<dbh_config> is in the C<cgiapp_init>
+stage of L<CGI::Application|CGI::Application>. If this method is called after the database handle
+has already been accessed, then it will die with an error message.
+
+=head3 Automatic configuration using CGI::App instance parameters
+
+An alternative to explicitly calling C<dbh_config> in your application
+is to rely on the presence of specific instance parameters that allow the
+plugin to configure itself.
+
+If you set the CGI::App parameter C<::Plugin::DBH::dbh_config> to
+an array reference the contents of that array will be used as parameters to
+C<dbh_config> (if it has not been explicitly called before).
+
+The code in the synopsis can be rewritten as
+
+ use CGI::Application::Plugin::DBH (qw/dbh/);
+ # no longer a need to import dbh_config
+
+ sub cgiapp_init {
+ # you do not need to do anything here
+ }
+
+ sub my_run_mode {
+
+ # this part stays unchanged
+
+ ....
+
+ }
+
+and in the instance script ( or instance configuration file, if you have)
+
+ $app->param('::Plugin::DBH::dbh_config' =>
+ [ $data_source, $username, $auth, \%attr ] );
+
+If you want to configure more than one handle, set up a hash with the handle names
+as keys:
+
+ $app->param('::Plugin::DBH::dbh_config' =>
+ { my_handle => [ $data_source, $username, $auth, \%attr ] ,
+ my_other_handle => [ $data_source, $username, $auth, \%attr ]
+ } );
+
+
+=head3 Automatic configuration with DBI environment variables
+
+If you do not set any parameters, and do not call C<dbh_config>, this plugin
+checks to see if you set the DBI environment variable C<DBI_DSN>. If present,
+this DSN will be used for the default handle. Note that the DBI documentation
+does not encourage using this method (especially in the context of web applications),
+that you will most likely have to also set C<DBI_USER> and C<DBI_PASS>, and
+that this can only be used for the default handle.
+
+
+=head2 dbh_default_name()
+
+ sub my_runmode {
+ my $self = shift;
+
+ my $old_handle_name = $self->dbh_default_name('my_handle');
+ $self->some_legacy_code(); # some_legacy_code() will get "my_handle"
+ # when it calls $self->dbh() without parameters
+
+ $self->dbh_default_name($old_handle_name); # Return to normal.
+ }
+
+Can be used to alter the name of the handle that is returned by dbh() when
+called with no parameters. It can even be used to alter the name used for the
+unamed handle if called before dbh_config().
+
+Using this method is completely optional. If you don't have a use for it don't
+use it. Internally the handle name "__cgi_application_plugin_dbh" is used to
+keep track of the unnamed handle unless it is changed by dbh_default_name()
+before a call to dbh_config() without a name parameter.
+
+=head1 SEE ALSO
+
+L<Ima::DBI|Ima::DBI> is similar, but has much more complexity and features.
+
+L<CGI::Application|CGI::Application>, L<DBI|DBI>, L<CGI::Application::Plugin::ValidateRM|CGI::Application::Plugin::ValidateRM>, perl(1)
+
+=head1 AUTHOR
+
+Mark Stosberg <mark at summersault.com>
+
+Multi Handle Support added by:
+Tony Fraser <tony at sybaspace.com>
+
+Autoconfig Support added by:
+Thilo Planz <thilo at cpan.org>
+
+=head1 LICENSE
+
+Copyright (C) 2004 Mark Stosberg <mark at summersault.com>
+
+This library is free software. You can modify and or distribute it under the same terms as Perl itself.
+
+=cut
+
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppAutoConfig.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppAutoConfig.pm?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppAutoConfig.pm (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppAutoConfig.pm Sat Jun 18 12:25:49 2011
@@ -1,0 +1,29 @@
+package TestAppAutoConfig;
+
+use strict;
+
+use CGI::Application;
+ at TestAppAutoConfig::ISA = qw(CGI::Application);
+
+use CGI::Application::Plugin::DBH (qw/dbh dbh_default_name/);
+
+sub cgiapp_init {
+ my $self = shift;
+
+
+}
+
+sub setup {
+ my $self = shift;
+
+ $self->start_mode('test_mode');
+
+ $self->run_modes(test_mode => 'test_mode' );
+}
+
+sub test_mode {
+ my $self = shift;
+ return 1;
+}
+
+1;
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppBasic.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppBasic.pm?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppBasic.pm (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppBasic.pm Sat Jun 18 12:25:49 2011
@@ -1,0 +1,31 @@
+package TestAppBasic;
+
+use strict;
+
+use CGI::Application;
+ at TestAppBasic::ISA = qw(CGI::Application);
+
+use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
+
+sub cgiapp_init {
+ my $self = shift;
+
+ $self->dbh_config('DBI:Mock:','','');
+
+}
+
+sub setup {
+ my $self = shift;
+
+ $self->start_mode('test_mode');
+
+ $self->run_modes(test_mode => 'test_mode' );
+}
+
+sub test_mode {
+ my $self = shift;
+ return 1;
+}
+
+
+1;
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppExistingDBH.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppExistingDBH.pm?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppExistingDBH.pm (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppExistingDBH.pm Sat Jun 18 12:25:49 2011
@@ -1,0 +1,33 @@
+package TestAppExistingDBH;
+
+use strict;
+
+use CGI::Application;
+ at TestAppExistingDBH::ISA = qw(CGI::Application);
+
+use CGI::Application::Plugin::DBH (qw/dbh_config dbh/);
+
+sub cgiapp_init {
+ my $self = shift;
+
+ require DBI;
+ my $dbh = DBI->connect('DBI:Mock:','','');
+ $self->dbh_config($dbh);
+
+}
+
+sub setup {
+ my $self = shift;
+
+ $self->start_mode('test_mode');
+
+ $self->run_modes(test_mode => 'test_mode' );
+}
+
+sub test_mode {
+ my $self = shift;
+ return 1;
+}
+
+
+1;
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppMultiHandle.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppMultiHandle.pm?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppMultiHandle.pm (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/TestAppMultiHandle.pm Sat Jun 18 12:25:49 2011
@@ -1,0 +1,25 @@
+package TestAppMultiHandle;
+
+use strict;
+
+use CGI::Application;
+use TestAppBasic;
+ at TestAppMultiHandle::ISA = qw(TestAppBasic);
+
+use CGI::Application::Plugin::DBH (qw/dbh_default_name dbh_config dbh/);
+
+sub cgiapp_init {
+ my $self = shift;
+
+ $self->dbh_config('handle1', [ 'DBI:Mock:','','' ]);
+ $self->dbh_config('handle2', $self->dbh('handle1'));
+
+ $self->param('orig_name1', $self->dbh_default_name('handle1'));
+ $self->dbh_config('handle3', $self->dbh);
+
+ $self->param('orig_name2', $self->dbh_default_name('handle4'));
+ $self->dbh_config('DBI:Mock:','','');
+
+ $self->dbh_default_name($self->param('orig_name1'));
+
+}
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/auto_config.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/auto_config.t?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/auto_config.t (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/auto_config.t Sat Jun 18 12:25:49 2011
@@ -1,0 +1,79 @@
+use Test::More qw/no_plan/;
+BEGIN { use_ok('CGI::Application::Plugin::DBH') };
+
+use lib './t';
+use strict;
+
+
+#### Test DBI environment variables
+
+
+$ENV{CGI_APP_RETURN_ONLY} = 1;
+$ENV{DBI_DSN}='dbi:Mock:';
+$ENV{DBI_USER}='';
+$ENV{DBI_PASS}='';
+
+use TestAppAutoConfig;
+
+my $t1_obj = TestAppAutoConfig->new();
+my $t1_output = $t1_obj->run();
+
+use UNIVERSAL;
+ok($t1_obj->dbh->isa('DBI::db'), 'dbh() method returns DBI handle');
+
+eval{ $t1_obj->dbh('blah') };
+ok ($@ =~ /^must call dbh_config/ , 'only default handle is configured');
+
+ok(
+ $t1_obj->dbh(
+ $t1_obj->dbh_default_name())
+ ->isa('DBI::db'), 'default handle is configured');
+
+
+#### Test CGI::App instance parameters (default handle)
+
+delete $ENV{DBI_DSN};
+
+$t1_obj = TestAppAutoConfig->new();
+$t1_obj->param('::Plugin::DBH::dbh_config' => [ 'dbi:Mock:', '', '',
+ {AutoCommit => 1, RaiseError => 1} ] );
+
+$t1_output = $t1_obj->run();
+
+ok($t1_obj->dbh->isa('DBI::db'), 'dbh() method returns DBI handle');
+
+eval{ $t1_obj->dbh('blah') };
+ok ($@ =~ /^must call dbh_config/ , 'only default handle is configured');
+
+ok(
+ $t1_obj->dbh(
+ $t1_obj->dbh_default_name())
+ ->isa('DBI::db'), 'default handle is configured');
+
+#### Test CGI::App instance parameters (two handles)
+
+$t1_obj = TestAppAutoConfig->new();
+$t1_obj->param('::Plugin::DBH::dbh_config' =>
+ { handle1 => [ 'dbi:Mock:', '', '', {AutoCommit => 1, RaiseError => 1} ],
+ handle2 => [ 'dbi:Mock:', '', '', {AutoCommit => 1, RaiseError => 1} ]}
+ );
+
+$t1_obj->dbh_default_name('handle1');
+
+$t1_output = $t1_obj->run();
+
+ok($t1_obj->dbh->isa('DBI::db'), 'dbh() method returns DBI handle');
+
+eval{ $t1_obj->dbh('blah') };
+ok ($@ =~ /^must call dbh_config/ , 'only handle1 and handle2 are configured');
+
+ok(
+ $t1_obj->dbh('handle1')
+ ->isa('DBI::db'), 'handle1 is configured');
+
+ok(
+ $t1_obj->dbh('handle2')
+ ->isa('DBI::db'), 'handle2 is configured');
+
+
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/basic.t?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/basic.t (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/basic.t Sat Jun 18 12:25:49 2011
@@ -1,0 +1,15 @@
+use Test::More qw/no_plan/;
+BEGIN { use_ok('CGI::Application::Plugin::DBH') };
+
+use lib './t';
+use strict;
+
+$ENV{CGI_APP_RETURN_ONLY} = 1;
+
+use TestAppBasic;
+my $t1_obj = TestAppBasic->new();
+my $t1_output = $t1_obj->run();
+
+use UNIVERSAL;
+ok($t1_obj->dbh->isa('DBI::db'), 'dbh() method returns DBI handle');
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/existing_dbh.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/existing_dbh.t?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/existing_dbh.t (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/existing_dbh.t Sat Jun 18 12:25:49 2011
@@ -1,0 +1,15 @@
+use Test::More qw/no_plan/;
+BEGIN { use_ok('CGI::Application::Plugin::DBH') };
+
+use lib './t';
+use strict;
+
+$ENV{CGI_APP_RETURN_ONLY} = 1;
+
+use TestAppExistingDBH;
+my $t1_obj = TestAppExistingDBH->new();
+my $t1_output = $t1_obj->run();
+
+use UNIVERSAL;
+ok($t1_obj->dbh->isa('DBI::db'), 'dbh() method returns DBI handle when using existing handle');
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/multi_handle.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/multi_handle.t?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/multi_handle.t (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/multi_handle.t Sat Jun 18 12:25:49 2011
@@ -1,0 +1,41 @@
+use Test::More qw/no_plan/;
+BEGIN { use_ok('CGI::Application::Plugin::DBH') };
+
+use lib './t';
+use strict;
+
+$ENV{CGI_APP_RETURN_ONLY} = 1;
+
+use TestAppMultiHandle;
+my $t1_obj = TestAppMultiHandle->new();
+my $t1_output = $t1_obj->run();
+
+ok($t1_obj->dbh_default_name eq "__cgi_application_plugin_dbh",
+ "deafult handle name was preserved");
+
+ok($t1_obj->param('orig_name1') eq "__cgi_application_plugin_dbh",
+ "name stored for first dbh_default_name() is correct");
+ok($t1_obj->param('orig_name2') eq "handle1",
+ "name stored for second dbh_default_name() is correct");
+
+use UNIVERSAL;
+
+# Default handle should be unset
+eval {$t1_obj->dbh};
+ok($@ =~ /must call dbh_config/, 'dbh() method dies for default handle');
+
+# We should have 4 named handles
+ok($t1_obj->dbh('handle1')->isa('DBI::db'), 'dbh("handle1") method returns DBI handle');
+ok($t1_obj->dbh('handle2')->isa('DBI::db'), 'dbh("handle2") method returns DBI handle');
+ok($t1_obj->dbh('handle3')->isa('DBI::db'), 'dbh("handle3") method returns DBI handle');
+ok($t1_obj->dbh('handle4')->isa('DBI::db'), 'dbh("handle4") method returns DBI handle');
+
+# Handles 2 and 3 should be the same as 1
+ok($t1_obj->dbh('handle2') == $t1_obj->dbh('handle1'), "handle2 is a copy of handle1");
+ok($t1_obj->dbh('handle3') == $t1_obj->dbh('handle1'), "handle3 is a copy of handle1");
+
+# Handle 4 should be different
+ok($t1_obj->dbh('handle1') != $t1_obj->dbh('handle4'), "handle4 is not a copy of handle1");
+ok($t1_obj->dbh('handle2') != $t1_obj->dbh('handle4'), "handle4 is not a copy of handle2");
+ok($t1_obj->dbh('handle3') != $t1_obj->dbh('handle4'), "handle4 is not a copy of handle3");
+
Added: branches/upstream/libcgi-application-plugin-dbh-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libcgi-application-plugin-dbh-perl/current/t/pod.t?rev=75945&op=file
==============================================================================
--- branches/upstream/libcgi-application-plugin-dbh-perl/current/t/pod.t (added)
+++ branches/upstream/libcgi-application-plugin-dbh-perl/current/t/pod.t Sat Jun 18 12:25:49 2011
@@ -1,0 +1,28 @@
+use Test::More;
+
+use File::Spec;
+use File::Find;
+use strict;
+
+eval {
+ require Test::Pod;
+ Test::Pod->import;
+};
+
+my @files;
+
+if ($@) {
+ plan skip_all => "Test::Pod required for testing POD";
+}
+else {
+ my $blib = File::Spec->catfile(qw(blib lib));
+ find(\&wanted, $blib);
+ plan tests => scalar @files;
+ foreach my $file (@files) {
+ pod_file_ok($file);
+ }
+}
+
+sub wanted {
+ push @files, $File::Find::name if /\.p(l|m|od)$/;
+}
More information about the Pkg-perl-cvs-commits
mailing list