Posted on 2009-06-30 16:49:05-07 by sirrobert
Moose isn't creating a constructor.
Hey all. I'm experienced with OO perl, but have only built a dozen or so classes with Moose. I'm trying to extend DBI in Moose but ... they don't seem to be friendly with each other =) Can someone please explain what's wrong here? I feel like it's probably something simple that I'm missing. When I "use base" the script runs without error. With "extends" it balks. Here's the error I'm getting:
Can't locate object method "new" via package "DBIX_sample" at ./test.pl line 7.
Here's my source: test.pl
#!/usr/bin/perl use strict; use warnings; use DBIX_sample; my $db = DBIX_sample->new; exit;
DBIX_sample.pm
package DBIX_sample; use Moose; ### Works when I 'use base' but not with 'extends.' extends 'DBI'; #use base 'DBI'; 1;
This is perl, v5.8.8 built for i686-linux
Direct Responses: 11095 | Write a response
Posted on 2009-06-30 17:06:35-07 by stvn in response to 11094
Re: Moose isn't creating a constructor.
You might want to take a look at MooseX::NonMoose to help with this. Moose does it's best to extend non-Moose classes, but with the 100 different ways to create objects in Perl OO it cannot always do the right thing. MooseX::NonMoose aims to actually fill the gap where core Moose fails. For your particular case, I would actually recommend delegation and not inheritance simply because DBI is a very complex module that internally uses things like tie() and XS so may very likely not play well with Moose subclassing. Not to mention that DBI is just a "factory" for DBI::db instances, which then in turn creates DBI::sth instances, and so simple subclassing of DBI is actually not very simple. You also might want to join the moose mailing list (moose@perl.org) or visit IRC #moose@irc.perl.org and ask this question there. I am pretty much the only Moose person who subscribes to these updates. If you ask there you will likely get much more help and insight. - Stevan
Direct Responses: 11096 | Write a response
Posted on 2009-06-30 17:22:27-07 by sirrobert in response to 11095
Re: Moose isn't creating a constructor.

Thanks, Stevan -- I appreciate it!

-Sir Robert
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.