Matt S Trout wrote:
On Wed, Oct 03, 2007 at 07:10:56PM +0100, Ian Docherty wrote:
I am using Moose, but I don't think that is the problem.

I want to over-ride 'new' whenever I create a 'Demo' object and add a Class::Workflow object to my DBIx::Class object. My code is:-
----------------
package MyApp::Domain::Result::Demo;

use Moose;
use Class::Workflow;

BEGIN {
extends 'DBIx::Class';
};

has 'workflow' => (
   is          => 'rw',
   isa         => 'Class::Workflow',
);

__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('demo');
__PACKAGE__->add_columns(qw(id name value state creator owner));
__PACKAGE__->set_primary_key('id');

sub new {
   my ($class, $attrs) = @_;

   my $workflow = Class::Workflow->new;
   my $new = $class->next::method($attrs);

# Neither of the following two work, both give the same error (see below)
   $new->{workflow} = $workflow;
   $new->workflow($workflow);
}

It would help if you actually returned $new at the end of the method ...
Drat. So obvious when you see it! It must have got deleted at some point since it was there to start. Thanks!

Regards
Ian

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]

Reply via email to