Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Role over subclasses

by mhearse (Chaplain)
on Nov 23, 2011 at 03:23 UTC ( [id://939582]=perlquestion: print w/replies, xml ) Need Help??

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

I have a module with multiple subclasses. I'm trying to figure out how 'Role' over these subclasses. I'm unsure of the terminology. I am using perl 5.10, and am wondering if this can be done without the use of a module, or perl6. Any examples would be helpful.
package Test1; use base 'Example1'; ## overrided method sub getObjectId { my $self = shift; my $arg = shift; return Other::Package::lookupId($arg); } 1; package Test2; use base 'Example2'; ## overrided method sub getObjectId { my $self = shift; my $arg = shift; return Other::Package::lookupId($arg); } 1; package Test3; use base 'Example2'; ## overrided method sub getObjectId { my $self = shift; my $arg = shift; return Other::Package::lookupId($arg); } 1;

Replies are listed 'Best First'.
Re: Role over subclasses
by grantm (Parson) on Nov 23, 2011 at 05:34 UTC
    I am ... wondering if this can be done without the use of a module

    Um perhaps it can but why on earth would you? A good place to find out about Roles in Perl is the Moose Manual. There are other ways to share related pieces of functionality *across* your class hierarchy but they will be considerably more work for the programmer, won't scale well across a large code base and will be harder to debug. If you're not going to use the power of pre-written code from CPAN then you're not using Perl to its full advantage.

      I am going to use MRO::Compat, I think it does what I need.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-25 01:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found