Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Authentication in a Many Database Scenario (again)

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


scott at simpzoid

May 15, 2012, 12:11 PM

Post #1 of 2 (121 views)
Permalink
Authentication in a Many Database Scenario (again)

Dear All,



I'd like to offer users their own database (so that their own data is
separate from other users) but use the same MVC code for all the user
databases. Following some helpful advice from this forum I have found the
documentation for ACCEPT_CONTEXT but unfortunately I don't have the smarts
to understand the documentation, could someone please explain some things to
me?

Essentially I reckon I want to change the __PACKAGE__->config in my model on
a per transaction basis. My current model looks like this

package EasyAC::Model::DB;



use strict;

use base 'Catalyst::Model::DBIC::Schema';



__PACKAGE__->config(

schema_class => 'EasyAC::Schema',



connect_info => {

dsn => 'dbi:mysql:easyac01',

user => 'me',

password => 'mypass',

AutoCommit => q{1},

}

);

The ACCEPT_CONTEXT documentation suggests:



Add a field to $c, like my_model_instance. Then write your ACCEPT_CONTEXT
method to look like this:

sub ACCEPT_CONTEXT {

my ( $self, $c ) = @_;



if ( my $per_request = $c->my_model_instance ) {

return $per_request;

} else {

my $new_instance = bless { %$self, c => $c }, ref($self);

Scalar::Util::weaken($new_instance->{c}); # or we have a circular
reference

$c->my_model_instance( $new_instance );

return $new_instance;

}

}



Question 1: how do I add a field like my_model_instance and from which
component do I add it? I did try obvious things like $c->my_model_instance
= {}.



Question 2: How do I replace the static connect_info with the per request
info (I have dsn, user and password in the stash). I'm guessing that I put
the connect_info into the hashref which I pass to ACCEPT_CONTEXT (i.e. the
hashref which becomes $self) and that Catalyst just magically resolves all
my worries?



I've also looked at the documentation for
<https://metacpan.org/module/Catalyst::Component::InstancePerContext>
Catalyst::Component::InstancePerContext. Which I cannot understand either:



Question 3: when the InstancePerContext documentation says # ... do your
thing here , I take it this means that I create a hash with my connect info
and return MyApp::Model::DB->new(%args). Does this then replace the
connect_info in MyApp::Model::DB?



Question 4: Should I give up as none of the above are remotely correct and
I obviously lack the intelligence to use a sophisticated tool like Catalyst?



Regards,

Scott


romkey at romkey

May 15, 2012, 12:29 PM

Post #2 of 2 (119 views)
Permalink
Re: Authentication in a Many Database Scenario (again) [In reply to]

On May 15, 2012, at 3:11 PM, <scott [at] simpzoid> <scott [at] simpzoid> wrote:
> I’d like to offer users their own database (so that their own data is separate from other users) but use the same MVC code for all the user databases. Following some helpful advice from this forum I have found the documentation for ACCEPT_CONTEXT but unfortunately I don’t have the smarts to understand the documentation, could someone please explain some things to me?


Forgive me if I've missed something but why not just write your model code and then reuse it by using it as a base class for each of your user databases?

So if your reusable model is EasyAC::Model::DB then you would just reuse it by create another model that extends it:

package AnApp::Model::DB;

use Moose;
use namespace::autoclean;
BEGIN { extends 'EasyAC::Model::DB'; }

1;


Put the config information for that superclass in the config file for that application and you're all set.

There should be more information on how to do this in http://search.cpan.org/~zarquon/Catalyst-Manual-5.9004/lib/Catalyst/Manual/ExtendingCatalyst.pod

- john romkey
http://romkey.com/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.