I've been working on some documentation for dbi models.
- http://brainbuz.org/techinfo/Catalyst-Model-Simple-Tutorial.html
or
- https://github.com/brainbuz/Catalyst--Model--Simple--Tutorial
You would create a single model to connect to each database. Then you would create submodels for each group of methods, I frequently group them by table.
# Parent MODEL
package BoPeep::Model::BoPeep;
use strict;
use warnings;
use DBIx::Simple ;
use parent 'Catalyst::Model::DBI';
__PACKAGE__->config(
dsn => BoPeep->config->{dsn} ,
user => BoPeep->config->{user} ,
password => BoPeep->config->{password} ,
);
use Moose ; #use Moose immediately before calling
#on Moose to extend the object
has db=>(
is =>'ro',
isa=>'DBIx::Simple',
lazy_build=> 1,
# If we don't want to handle all dbis methods,
# specify those that we want.
# handles=> [qw/query flat /],
);
sub _build_db {
my $self = shift ;
return DBIx::Simple->connect($self->dbh);
} ;
# Child Model
package BoPeep::Model::BoPeep::Flock;
use Moose;
use BoPeep;
use namespace::autoclean;
extends 'BoPeep::Model::BoPeep';
sub List {
my $self = shift ;
my $db = $self->db ;
my @sheep = $db->query('SELECT * FROM flock')->flat ;
return @sheep ;
}
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
1;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|