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"


In reply to You cannot override 'getnew' because it has no super method by metaperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.