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

Howto create a Moose baseclass/superclass/contract? Moose equivalent of Module::Pluggable? Favorite way to create base/super class?

by Anonymous Monk
on Dec 26, 2012 at 11:40 UTC ( #1010362=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Howto create a Moose baseclass/superclass/contract? Moose equivalent of Module::Pluggable? Favorite way to create base/super class?

The use case is some app that does something with different backends

package iAmInYourIsa; sub dothis { croak "subclass must implement dothis" } ...

so one backend is

package iAmInYourIsa::CGI; use parent 'iAmInYourIsa'; use CGI; sub dothis { ... my $q = CGI->new ... $q->param ... }

another is iAmInYourIsa::Tk and so on and so forth?

I could cobble something using Module::Pluggable, but the verbiage is all wrong :)

Comment on Howto create a Moose baseclass/superclass/contract? Moose equivalent of Module::Pluggable? Favorite way to create base/super class?
Select or Download Code
Replies are listed 'Best First'.
Re: Howto create a Moose baseclass/superclass/contract? Moose equivalent of Module::Pluggable? Favorite way to create base/super class?
by tobyink (Abbot) on Dec 26, 2012 at 14:52 UTC

    Don't use an abstract base class; use roles...

    { package IAmNotInYourIsa; use Moose::Role; requires 'dothis'; } { package My::CGI; use Moose; with 'IAmNotInYourIsa'; use CGI; sub dothis { ... my $q = CGI->new ... $q->param ... } } My::CGI->isa('IAmNotInYourIsa'); # false My::CGI->does('IAmNotInYourIsa'); # true!

    A good example can be seen in the Ask distribution on CPAN, where there are different implementations for STDIN/STDOUT, Tk, etc, each of which include:

    with 'Ask::API';

    Ask uses Moo rather than Moose, but the principle is the same.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Howto create a Moose baseclass/superclass/contract? Moose equivalent of Module::Pluggable? Favorite way to create base/super class?
by karlgoethebier (Vicar) on Dec 26, 2012 at 14:52 UTC

    Reading some manuals? Moose::Manual a.s.o.

    Saying "Please..."?

    Perhaps this helps? Regards, Karl

    P.S.:my goose was too fat. OK - Still got a hangover

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2015-07-29 23:22 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 (269 votes), past polls