[Catalyst] Class::DBI::ViewLoader::Pg in model helper tools

Gavin Henry ghenry at perl.me.uk
Mon Jan 16 14:39:05 CET 2006


<quote who="Chisel Wright">
> On Sun, Jan 15, 2006 at 11:51:11AM -0000, Gavin Henry wrote:
>> Dear List,
>>
>> Is it possible to add this Loader when creating Models?
>>
>> I noticed last night when using Catalyst::Enzyme that it missed some of
>> my
>> Postgresql views.
>
> OK, I work with the author of this module. He's out-of-office this
> week, but having a quick look around our work repository, he has
> SomeApp::M::SomeAppDB which looks something like the pasted code below.
>
> There might be better ways, but I guess this works for him.
>
> Chisel

Thanks Chisel. I really meant for the commandline tools to include this
too? Like a view option or something?

Maybe best just done like below.

>
> ---- cut here ----
> ckage SomeApp::M::SomeAppDB;
>
> use strict;
> use warnings;
>
> use base 'Catalyst::Model::CDBI';
>
> use Class::DBI::ViewLoader;
>
> #
> # Load global config in to local namespace and populate local config.
> #
> my $cfg = SomeApp->config->{local_cfg};
>
> __PACKAGE__->config(
>     dsn           => $cfg->dsn,
>     user          => $cfg->dbuser,
>     password      => $cfg->dbpass,
>     options       => {
>         RaiseError => 1,
>         AutoCommit => 1,
>         pg_enable_utf8 => 1,
>     },
>     relationships => 1,
>     additional_classes => [qw/
>         Class::DBI::Plugin::RetrieveAll
>         Class::DBI::AbstractSearch
>     /],
> );
>
> sub new {
>     my $self = shift;
>     my($c) = @_;
>     $self = $self->NEXT::new(@_);
>
>     my $loader = new Class::DBI::ViewLoader(
> 	    %{$self->config},
> 	    namespace => 'SomeApp::M::SomeAppDB'
> 	);
>
>     my @loaded = $loader->load_views;
>
>     if (@loaded) {
>         my $views = join(" ", map { $_->table } @loaded);
>
>         $c->log->debug("Loaded views: \"$views\"");
>     }
>     else {
>         $c->log->debug("No views loaded");
>     }
>
>     return $self;
> }
>
> 1;
> ---- cut here ----
>
> --
> Chisel Wright
> e: chisel at herlpacker.co.uk
> w: http://www.herlpacker.co.uk/
>
> This is not an automated signature. I type this in to the bottom of every
> message.
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>




More information about the Catalyst mailing list