[Catalyst] Class::DBI::ViewLoader::Pg in model helper tools
Chisel Wright
chisel at herlpacker.co.uk
Mon Jan 16 12:24:57 CET 2006
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
---- 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.
More information about the Catalyst
mailing list