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

Mailing List Archive: Catalyst: Users

Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters

 

 

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


nick at webcraftcs

Jun 26, 2012, 8:30 AM

Post #1 of 5 (557 views)
Permalink
Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters

Using the Catalyst-TraitFor-Component-ConfigPerSite modules, I am able
to set up various database connections on a per-site basis and this
works well.

Can anyone tell me how I can extend this to access additional per-site
information from the config file which will allow me to e.g. set up
per-site file_paths to feed into the fs_column_path (using
<http://search.cpan.org/perldoc?DBIx%3A%3AClass%3A%3AInflateColumn%3A%3AFS>DBIx::Class::InflateColumn::FS)
within the Model::DB package?

Currently, $self->schema->file_path() extracts the config item from the
default <Model::DB> section. I want to extract the file_path from the
website1 section of the config file.

Any help would be greatly appreciated.

Thank you.


Currently, my config file contains:
====================

<Model::DB>
schema_class default::Schema
<connect_info>
dsn dbi:mysql:defaultdb
user xxxx
password xxxx
</connect_info>
file_path /path/to/site/default
</Model::DB>

<TraitFor::Component::ConfigPerSite>
<website1.com>
<Model::DB>
schema_class website1::Schema
<connect_info>
dsn dbi:mysql:website1db
user xxxx
password xxxx
</connect_info>
instance_cache_key website1_model_db
file_path /path/to/site/website1
</Model::DB>
</website1.com>
</TraitFor::Component::ConfigPerSite>


The DB model file:
===========
package myapp::Model::DB;

use strict;
use Moose;
extends 'Catalyst::Model::DBIC::Schema';
with qw(Catalyst::TraitFor::Model::DBIC::ConfigPerSite);

__PACKAGE__->config(
traits => 'SchemaProxy',
);

around 'COMPONENT' => sub {
my ($orig, $class, $app, $args) = @_;
my $self = $class->$orig($app, $args);

$self->schema->source('Wcbfile')->column_info('wcbfiles_file')->{fs_column_path}
= $self->schema->file_path();
return $self;
};


1;


aaron.trevena at gmail

Jun 27, 2012, 3:07 AM

Post #2 of 5 (528 views)
Permalink
Re: Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters [In reply to]

Hi Nick,

Currently I think it just handles the basic fields I'm afraid.

You can probably sub-class it to copy more fields, or wait until I
patch it to provide access to all the fields in the configuration
(something that is clearly necessary) - which will be at least a
couple of days.

You can fork and make a pull request at
https://github.com/hashbangperl/Catalyst-TraitFor-Component-ConfigPerSite
or send a patch by email the old fashioned way if you can make it work
yourself quicker than I get around to it (quite probable).

Can you file this as a bug at rt.cpan.org so that I can keep track and
poke me in a couple of days if you don't hear anything from me?

I'm probably missing a trick somewhere so if any catalyst devs want to
have a look and suggest a nice way to handle this I'd really
appreciate it :)

regards,

A.

--
Aaron J Trevena, BSc Hons
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Consulting

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


nick at webcraftcs

Jun 28, 2012, 2:45 AM

Post #3 of 5 (522 views)
Permalink
Re: Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters [In reply to]

Hi Aaron,

Many thanks for the quick response.

I have filed a bug report #78089

I hope to take a look at the package shortly and will post any solution
I come up with.

Kind regards,

Nick


On 27/06/12 11:07, Aaron Trevena wrote:
> Hi Nick,
>
> Currently I think it just handles the basic fields I'm afraid.
>
> You can probably sub-class it to copy more fields, or wait until I
> patch it to provide access to all the fields in the configuration
> (something that is clearly necessary) - which will be at least a
> couple of days.
>
> You can fork and make a pull request at
> https://github.com/hashbangperl/Catalyst-TraitFor-Component-ConfigPerSite
> or send a patch by email the old fashioned way if you can make it work
> yourself quicker than I get around to it (quite probable).
>
> Can you file this as a bug at rt.cpan.org so that I can keep track and
> poke me in a couple of days if you don't hear anything from me?
>
> I'm probably missing a trick somewhere so if any catalyst devs want to
> have a look and suggest a nice way to handle this I'd really
> appreciate it :)
>
> regards,
>
> A.
>


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


aaron.trevena at gmail

Jun 28, 2012, 3:09 AM

Post #4 of 5 (524 views)
Permalink
Re: Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters [In reply to]

On 28 June 2012 10:45, Nick <nick [at] webcraftcs> wrote:
> Many thanks for the quick response.

No problem - I'm annoyed I didn't spot your mail to the list sooner.

> I have filed a bug report #78089
>
> I hope to take a look at the package shortly and will post any solution I
> come up with.

That's great!

Let me know if you come across any other problems or unclear documentation.

Thanks,

Aaron

--
Aaron J Trevena, BSc Hons
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Consulting

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


aaron.trevena at gmail

Jul 13, 2012, 12:45 PM

Post #5 of 5 (476 views)
Permalink
Re: Catalyst-TraitFor-Component-ConfigPerSite - How to access additional per-site config parameters [In reply to]

I've revisited this a couple of times wondering what I was missing, I
think I found what I was overlooking,

you're using http://search.cpan.org/dist/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/SchemaProxy.pm
to provide that file_path method.

I'll see if I can include that in the tests and replicate the problem
- it would be nice if that trait JustWorks(TM) with the PerSite trait,
I was scratching my head wondering what I was doing wrong in
PerSiteConfig (I might still be doing something wrong, hopefully this
will give me a clue, if so)

--
Aaron J Trevena, BSc Hons
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Consulting

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

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.