[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] Patch: DBH plugin configuration


Hi Mark,

I think I would accept a patch for this functionality to '::Plugin::DBH' if you wanted to make it work. I can't say I'm excited enough to code it
myself, though. :)

I'll take your word on that :-)

Below is a patch.
It still passes the the current test suite and I can make additional tests for the new functionality if the patch gets accepted.

The syntax changed a little from my previous post, here is the POD I wrote

     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 ]
                       }  );






Cheers,

Thilo


============ diff output against CPAN 2.00 version ==========

< croak "must call dbh_config() before calling dbh()." unless $self->{__DBH_CONFIG}{$name};
<
---
>       unless ($self->{__DBH_CONFIG}{$name}){
>               __auto_config($self, $name);
> croak "must call dbh_config() before calling dbh()." unless $self->{__DBH_CONFIG}{$name};
>       }
>
68a72,100
> 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 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 unless $params;
>               dbh_config($app, $name, $params);
>               return;
>        }
>
> croak "Parameter ::Plugin::DBH::dbh_config must be an array or hash reference";
> }
>
>
167a200,242
> =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 ]
>               }  );
>
>
>
>
200a276,278
>
> Autoconfig Support added by:
> Thilo Planz <suppressed>


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.