[Catalyst] RE: Model Testing Problems.

John Karr brainbuz at brainbuz.org
Mon Aug 15 19:50:14 GMT 2011


========================
# Parent Model
package BoPeep::Model::DBI;
 
use strict; use warnings;
use DBIx::Simple ;
use parent 'Catalyst::Model::DBI';
 
__PACKAGE__->config( .. stuff .. );

use Moose ; 
has db=>(The following is 
        is =>'ro',
        isa=>'DBIx::Simple',
        lazy_build=> 1, );
sub _build_db {
        my $self = shift ;
        return DBIx::Simple->connect($self->dbh); } 

=========================
# Method Model		
package BoPeep::Model::DBI::Flock;
use Moose;
use namespace::autoclean;
extends 'BoPeep::Model::DBI';

sub CountSheep {
	my $self = shift ;
	my $q = 'SELECT COUNT (*) FROM flock' ;
	my $countedsheep = $self->db->query( $q )->list ;
	return $countedsheep ; }

=========================
## Finally an attempt at a test script looks something like:

use strict; use warnings; use Carp::Always ;
use Test::More;

BEGIN { use_ok 'BoPeep::Model::DBI::Flock' }
use BoPeep::Model::DBI::Flock ; 
my $BoPeep = BoPeep::Model::DBI::Flock->new() || 
		die "cant make new object"; #also tried connect
ok( $BoPeep, 'Object evaluates as true!' );
is( $BoPeep->model('DBI::Flock')->CountSheep(), 3 , 'CountSheep. There are 3 sheep in BoPeeps flock' ) ; 

##############################

The use statement(s) are successful. If I comment script after use, it runs.
Looked at Catalyst::Test docs but it doesn't seem relevant here?

The error from trying to create the new instance is something like:
[info] BoPeep powered by Catalyst 5.80033
t/model_BoPeep_Flock.t .. 1/? Can't call method "log" on an undefined value at /.../perl5/.../Catalyst/Model/DBI.pm line 58
	Catalyst::Model::DBI::new('BoPeep::Model::DBI::Flock') called at t/model_BoPeep_Flock.t line 13


More information about the Catalyst mailing list