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

Mailing List Archive: Catalyst: Users

Reasonable way to get $c->config into Result class?

 

 

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


will at serensoft

Dec 12, 2011, 4:49 PM

Post #1 of 3 (291 views)
Permalink
Reasonable way to get $c->config into Result class?

We have a Catalyst app where incidents can have attachments, and the
attachments are stored in the filesystem (MySql backend is lethargic for
in-DB binary blobs).

Right now we're using a package global for storing the file-path-root, but
obviously this should be handled via config somehow. Is there an elegant
way to use MyApp.conf to set up a file-path that can get to $self->config
consistently?

If we use
package MyApp::Schema::DB::Result::Incident;
#...
has 'config' => ( is => 'rw' );
#...
then in the Controller we have to inject something into $incident->config
manually at create-time like so:

package MyApp::Web::Controller::Incident;
#...
my $incident = $c->model('MyApp::Incident')->find({ id => $id });
$incident->config( $c->config );

But that only works in the context of a controller. If instead, we're
coming in from a related record, such as an attachment, then
$attachment->incident->config won't have any info, and no way to get it.

I can see where DBIx::Class::Schema::Config allows pre-configuring
credentials to connect to a database, but that's not what we're looking for
here.

Right now we have the file-path config stored in a global (yecch!) in the
Result class, but would much rather have it in myapp.conf somehow...

Clue stick welcome.


--
--
will trillich -- http://faq.serensoft.com/
"The truth is that many people set rules to keep
from making decisions." -- Mike Krzyzewski


davewood at gmx

Dec 12, 2011, 11:49 PM

Post #2 of 3 (280 views)
Permalink
Re: Reasonable way to get $c->config into Result class? [In reply to]

http://wiki.catalystframework.org/wiki/wikicookbook/configpass2schema

I hope that solves your problem. I am in a bit of a hurry and didn't
read your mail very carefully

david

On 13 December 2011 01:49, will trillich <will [at] serensoft> wrote:
> We have a Catalyst app where incidents can have attachments, and the
> attachments are stored in the filesystem (MySql backend is lethargic for
> in-DB binary blobs).
>
> Right now we're using a package global for storing the file-path-root, but
> obviously this should be handled via config somehow. Is there an elegant way
> to use MyApp.conf to set up a file-path that can get to $self->config
> consistently?
>
> If we use
>     package MyApp::Schema::DB::Result::Incident;
>     #...
>     has 'config' => ( is => 'rw' );
>     #...
> then in the Controller we have to inject something into $incident->config
> manually at create-time like so:
>
>     package MyApp::Web::Controller::Incident;
>     #...
>     my $incident = $c->model('MyApp::Incident')->find({ id => $id });
>     $incident->config( $c->config );
>
> But that only works in the context of a controller. If instead, we're coming
> in from a related record, such as an attachment, then
> $attachment->incident->config won't have any info, and no way to get it.
>
> I can see where DBIx::Class::Schema::Config allows pre-configuring
> credentials to connect to a database, but that's not what we're looking for
> here.
>
> Right now we have the file-path config stored in a global (yecch!) in the
> Result class, but would much rather have it in myapp.conf somehow...
>
> Clue stick welcome.
>
>
> --
> --
> will trillich -- http://faq.serensoft.com/
> "The truth is that many people set rules to keep
> from making decisions." -- Mike Krzyzewski
>
> _______________________________________________
> 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/
>

_______________________________________________
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/


will.trillich at serensoft

Dec 14, 2011, 7:17 AM

Post #3 of 3 (276 views)
Permalink
Re: Reasonable way to get $c->config into Result class? [In reply to]

That does look promising. I'll take a look -- thanks!


On Tue, Dec 13, 2011 at 7:49 AM, David Schmidt <davewood [at] gmx> wrote:

> http://wiki.catalystframework.org/wiki/wikicookbook/configpass2schema
>
> I hope that solves your problem. I am in a bit of a hurry and didn't
> read your mail very carefully
>
> david
>
> On 13 December 2011 01:49, will trillich <will [at] serensoft> wrote:
> > We have a Catalyst app where incidents can have attachments, and the
> > attachments are stored in the filesystem (MySql backend is lethargic for
> > in-DB binary blobs).
> >
> > Right now we're using a package global for storing the file-path-root,
> but
> > obviously this should be handled via config somehow. Is there an elegant
> way
> > to use MyApp.conf to set up a file-path that can get to $self->config
> > consistently?
> >
> > If we use
> > package MyApp::Schema::DB::Result::Incident;
> > #...
> > has 'config' => ( is => 'rw' );
> > #...
> > then in the Controller we have to inject something into $incident->config
> > manually at create-time like so:
> >
> > package MyApp::Web::Controller::Incident;
> > #...
> > my $incident = $c->model('MyApp::Incident')->find({ id => $id });
> > $incident->config( $c->config );
> >
> > But that only works in the context of a controller. If instead, we're
> coming
> > in from a related record, such as an attachment, then
> > $attachment->incident->config won't have any info, and no way to get it.
> >
> > I can see where DBIx::Class::Schema::Config allows pre-configuring
> > credentials to connect to a database, but that's not what we're looking
> for
> > here.
> >
> > Right now we have the file-path config stored in a global (yecch!) in the
> > Result class, but would much rather have it in myapp.conf somehow...
> >
> > Clue stick welcome.
> >
> >
> > --
> > --
> > will trillich -- http://faq.serensoft.com/
> > "The truth is that many people set rules to keep
> > from making decisions." -- Mike Krzyzewski
> >
> > _______________________________________________
> > 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/
> >
>
> _______________________________________________
> 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/
>



--
"We act as though comfort and luxury were the chief requirements of life,
when all that we need to make us happy is something to be enthusiastic
about." -- Albert Einstein

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.