I'm using Moo.pm ($VERSION = '2.000001';) and using 'extends' to build up inheritance.

This works fine, yet if I make an edit that will not compile (not my intention, but it sometimes happens, in this case the semi colon after handleDUM), the compile error is messed up:

mheSim.pl -type CRANESWL

Can't locate object method "checkArgs" via package "CRANESWL" at mheSim.pl line 37.

Please see my code below. Note that I've cut it down to be as short as possible to be relevant to this problem

My guess is that I'm not using Moo correctly and I should be using either Tiny::Roles or Moo::Roles, but without the compilation error it all works fine.

package MHE; use Data::Dumper; ################################################## use Moo; use Sub::Quote; my $args = (); has heartbeat => ( is => 'ro', default => sub { $args->{heartbeat} || 10; } ); ################################################## # End of oo setup ################################################## sub checkArgs { my ($self, $args) = @_; pod2usage( -msg => "No IP address specified\n", -verbose => 1 ) unless $args->{ip}; } 1;
and
package CRANESWL; use Moo; extends 'MHE'; has type => ( is => 'ro', default => 'CRANESWL', ); ################################################## # Handle incoming messages ################################################## # hash to define what sub to call dependant upon what msg type my $msgTypes = { DUM => \&handleDUM; }; 1;

and the main script:

#!/usr/bin/perl -w use FindBin qw($Bin); use Getopt::Long; use strict; # Set Library path for MHE modules use lib "$Bin/../lib"; use MHE; my $opts = { }; GetOptions($opts, 'type:s', ); # Use the object dependant upon the requested Type eval "use MHE::$opts->{type} qw(sendHeartbeat)"; my $mhe = $opts->{type}->new; $mhe->checkArgs($opts);

In reply to Using Moo.pm and compilation errors by walshy

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.