Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Abstract Methods in Moose

by brap (Pilgrim)
on Dec 11, 2009 at 19:45 UTC ( #812424=note: print w/ replies, xml ) Need Help??


in reply to Abstract Methods in Moose

I could be way off (just trying to learn Moose myself), but are you maybe looking for

requires 'get_widget_type';

in the base class by chance?


Comment on Re: Abstract Methods in Moose
Download Code
Re^2: Abstract Methods in Moose
by crashtest (Curate) on Dec 11, 2009 at 20:17 UTC

    Hm. I believe the requires is provided by Moose::Role, and hence has the limitations outlined in the documentation.

    What it comes down is that while I can use a role to require a method definition directly in a class, I can't "defer" the method definition until later in the class hierarchy. That is, the following would work:

    package WidgetRole; use Moose::Role; requires 'get_widget_type'; package AbstractWidget; use Moose; with 'WidgetRole'; sub get_widget_type{ "IAmAbstract" }
    but the following (which is what I'd want) wouldn't:
    package WidgetRole; use Moose::Role; requires 'get_widget_type'; package AbstractWidget; use Moose; with 'WidgetRole'; package SnazzyWidget; use Moose; extends 'AbstractWidget'; sub get_widget_type{ "BasicWidget" } # throws error and dies

    So I don't think roles/using requires is what I am looking for. But maybe I'm wrong - I have all of five days of experience with Moose!

      imho roles are theabstract part and the class that consumes is muchh more concrete
      Why do you have a role and and a base class? You should use a role instead of a base class. All you need is
      package Widget::Role; # Formerly Widget::Abstract use Moose::Role; requires qw( get_widget_type ); # Abstract methods ... # Other attributes and methods. 1;
      package Widget::Snazzy; use Moose; with qw( Widget::Role ); sub get_widget_type { __PACKAGE__ } ... 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://812424]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2015-07-06 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (72 votes), past polls