Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

You cannot override 'getnew' because it has no super method

by metaperl (Curate)
on Aug 26, 2011 at 13:52 UTC ( [id://922614]=perlquestion: print w/replies, xml ) Need Help??

metaperl has asked for the wisdom of the Perl Monks concerning the following question:

I have a base class which implements a getnew method:
package Local::Quickbooks; # ABSTRACT: Base class for our local interface to XML::Quickbooks use Math::Fraction; use TJ; use Moose; extends qw(XML::Quickbooks); has 'getnewsql' => (is => 'rw', lazy_build => 1); has 'exportmode' => ( is => 'rw' ); has 'recordi' => ( is => 'rw' ); has 'recordcount' => ( is => 'rw' ); has 'progressbar' => ( is => 'rw' ); has 'manager_results' => ( is => 'rw', default => sub { use Data::MultiValuedHash; Data::MultiValuedHash- +>new } ); sub getnew { my ($self) = @_; use DBI; DBI->trace(1); $self->dbs->query($self->getnewsql)->hashes; } 1;
And I have a role whose purpose is to override the 'getnew' method:
package Local::Quickbooks::GetNewTicketData; use Moose::Role; override 'getnew' => sub { my ($self) = @_; my @row = $self->dbs->query( $self->getnewsql )->hashes; my %row; my %customerid; for my $row (@row) { if ( $row->{amount} < 0 ) { $row->{amount} *= -1; $row->{quantity} *= -1; } push @{ $row{ $row->{id} } }, $row; $customerid{ $row->{id} } = $row->{customer_listid}; } my @ret = map { my %row = ( CustomerRef => { ListID => $customerid{$_} }, transactions => $row{$_} ); \%row; } ( keys %row ); warn Dumper( 'Original Data', \@row, 'Mapped Data', \%row, 'Returned Data', \@ret ); return wantarray ? @ret : \@ret; }; 1;
And I have a child class which uses this role to override the base class 'getnew' method:
package Local::Quickbooks::InvoiceAdd; use Data::Dumper; use Data::Rmap qw(:all); use DateTime; use Moose; extends qw(XML::Quickbooks::Writer::InvoiceAdd Local::Quickbooks); with 'Local::Quickbooks::GetNewTicketData'; 1;
but when Moose tries to load the child class it throws this error:
*** unhandled exception in callback: *** You cannot override 'getnew' because it has no super method at C +:/strawberry/perl/site/lib/Moose/Meta/Class.pm line 521 *** Moose::Meta::Class::add_override_method_modifier('Moose::Met +a::Class=HASH(0xe9b969c)', 'getnew', 'CODE(0xe9d8fa4)', 'Local::Quick +books::GetNewTicketData') called at C:/strawberry/perl/site/lib/Moose +/Meta/Role/Application/ToClass.pm line 209 *** Moose::Meta::Role::Application::ToClass::apply_override_meth +od_modifiers('Moose::Meta::Role::Application::ToClass=HASH(0xe9d8864) +', 'Moose::Meta::Role=HASH(0xec09eac)', 'Moose::Meta::Class=HASH(0xe9 +b969c)') called at C:/strawberry/perl/site/lib/Moose/Meta/Role/Applic +ation.pm line 59 *** Moose::Meta::Role::Application::apply('Moose::Meta::Role::Ap +plication::ToClass=HASH(0xe9d8864)', 'Moose::Meta::Role=HASH(0xec09ea +c)', 'Moose::Meta::Class=HASH(0xe9b969c)') called at C:/strawberry/pe +rl/site/lib/Moose/Meta/Role/Application/ToClass.pm line 33 *** Moose::Meta::Role::Application::ToClass::apply('Moose::Meta: +:Role::Application::ToClass=HASH(0xe9d8864)', 'Moose::Meta::Role=HASH +(0xec09eac)', 'Moose::Meta::Class=HASH(0xe9b969c)', 'HASH(0xec0811c)' +) called at C:/strawberry/perl/site/lib/Moose/Meta/Role.pm line 482 *** Moose::Meta::Role::apply('Moose::Meta::Role=HASH(0xec09eac)' +, 'Moose::Meta::Class=HASH(0xe9b969c)') called at C:/strawberry/perl/ +site/lib/Moose/Util.pm line 154 *** Moose::Util::_apply_all_roles('Moose::Meta::Class=HASH(0xe9b +969c)', undef, 'Local::Quickbooks::GetNewTicketData') called at C:/st +rawberry/perl/site/lib/Moose/Util.pm line 93 *** Moose::Util::apply_all_roles('Moose::Meta::Class=HASH(0xe9b9 +69c)', 'Local::Quickbooks::GetNewTicketData') called at C:/strawberry +/perl/site/lib/Moose.pm line 65 *** Moose::with('Moose::Meta::Class=HASH(0xe9b969c)', 'Local::Qu +ickbooks::GetNewTicketData') called at C:/strawberry/perl/site/lib/Mo +ose/Exporter.pm line 356 *** Moose::with('Local::Quickbooks::GetNewTicketData') called at + c:\Users\thequietcenter\prg\biotrackthc\trunk\Local\lib/Local/Quickb +ooks/InvoiceAdd.pm line 10 *** require Local/Quickbooks/InvoiceAdd.pm called at c:\Users\th +equietcenter\prg\biotrackthc\trunk\Local\lib/Local/Quickbooks.pm line + 40 *** Local::Quickbooks::BEGIN() called at c:\Users\thequietcenter +\prg\biotrackthc\trunk\Local\lib/Local/Quickbooks/InvoiceAdd.pm line +0 *** eval {...} called at c:\Users\thequietcenter\prg\biotrackthc +\trunk\Local\lib/Local/Quickbooks/InvoiceAdd.pm line 0 *** require Local/Quickbooks.pm called at main.pm line 629 *** main::loadQuickbooks('Gtk2::MenuItem=HASH(0xb9f6384)') calle +d at C:\Users\thequietcenter\prg\biotrackthc\trunk\biotrackthc.pl lin +e 504 *** eval {...} called at C:\Users\thequietcenter\prg\biotrackthc +\trunk\biotrackthc.pl line 504 *** Compilation failed in require at c:\Users\thequietcenter\prg\bio +trackthc\trunk\Local\lib/Local/Quickbooks.pm line 40, <DATA> line 496 +. *** BEGIN failed--compilation aborted at c:\Users\thequietcenter\prg +\biotrackthc\trunk\Local\lib/Local/Quickbooks.pm line 40, <DATA> line + 496.

in other words

Moose is saying that I did not implement 'getnew' in a superclass even though it is clearly implemented there.



The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"

Replies are listed 'Best First'.
Re: You cannot override 'getnew' because it has no super method
by moritz (Cardinal) on Aug 26, 2011 at 14:09 UTC

    Whenever you suspect that a tool (module, perl compiler, whatever) has a problem, try to boil down the problem to the absolutely minimal case that could exhibit the problem. I've tried it here:

    package Local::Quickbooks; use Moose; sub getnew { } package Local::Quickbooks::GetNewTicketData; use Moose::Role; override 'getnew' => sub { }; package Local::Quickbooks::InvoiceAdd; use Moose; extends qw(Local::Quickbooks); with 'Local::Quickbooks::GetNewTicketData';

    On a perl 5.14.1 with Moose 2.0009 this doesn't produce an error.

    So I guess it's a metaperl bug rather than a Moose bug (or fixed, and your Moose is too old), and some of the other hundred classes in your code do something odd, and causes some odd behavior on Moose along the way.

    So, create a copy of your project, and successively delete stuff from it until the error goes away. When the error goes away, press "undo" in your editor, and look closely at the just restored code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://922614]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-03-28 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found