Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Migrate your perl project to Moose

by py_201 (Acolyte)
on Oct 17, 2011 at 06:43 UTC ( #931850=perlquestion: print w/ replies, xml ) Need Help??
py_201 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have been given a complex project written in Perl(back end). I have to now migrate it to MOOSE entirely using the OOPS concepts. As i am the only person working in this project on Perl. I have to learn Moose on my own and do the work. Please help me with some good tutorials, the Book to follow or some training available on MOOSE which will help me in my work. I have searched over web for same but did not get much help. Please share asap.

Thanks, Poonam

Comment on Migrate your perl project to Moose
Re: Migrate your perl project to Moose
by Khen1950fx (Canon) on Oct 17, 2011 at 07:30 UTC
      I think this is not exactly what the OP needs because it only helps you to extend classes in Mosse that where not written in Moosse themselves. If I understand correctly, the OP "wants" to re-write Perl code to use Moose. It's a very useful extension though if the OP can get away with only writing any new code in Moose and leave the rest untouched.
Re: Migrate your perl project to Moose
by moritz (Cardinal) on Oct 17, 2011 at 09:33 UTC
Re: Migrate your perl project to Moose
by zentara (Archbishop) on Oct 17, 2011 at 10:28 UTC
Re: Migrate your perl project to Moose
by tospo (Hermit) on Oct 17, 2011 at 10:28 UTC
    If you have been programming in object-oriented style previously then the move to Moose is not too difficult. The main thing to look for are all those attribute read/write boilerplate codes in the old classes, which might look something like this
    sub name { my $self = shift; my $new_value = shift; $self->{_name} = $new_value if defined $new_value; return $self->{_name}; }
    and translate to Moose code like this:
    has 'name' => ( is => 'rw', isa => 'Str', );
    So, first identify attributes of the class which store data and convert them to Moose using the "has" declaration. You will be left with methods in the original code that perform some action on the attributes and you can leave them mostly untouched except that you want to make sure you don't access the underlying blessed hash of attributes directly, so you want to change (in my example) all occurrences of $self->{_name} to $self->name throughout the code.
    This will get you a long way in converting your code to Moose style. It's all explained in detail in the Moose tutorials, start here. This one is quite helpful to quickly understand the differences between Moose and non-Moose OO code. To really make the most of Moose you should then look into things like Moose Roles etc, but for now this should get you going.
Reaped: Re: Migrate your perl project to Moose
by NodeReaper (Curate) on Oct 17, 2011 at 13:15 UTC
Re: Migrate your perl project to Moose
by TomDLux (Vicar) on Oct 17, 2011 at 14:56 UTC

    I've read a number of tutorials and used Moose on a couple of projects. Learning the basics are easy, figuring out the right way to do more complex things is hard.

    Roberto Signes' excellent workshop slides, "Moose is Perl" helped a lot in understanding advanced topics in Moose. I only wish he would turn it into a text article or book, rather than mere PowerPoint slides.

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

      The slides are available.


      TGI says moo

Re: Migrate your perl project to Moose
by jandrew (Hermit) on Oct 17, 2011 at 17:59 UTC

    I started by attempting some of the recipes in the Moose::Cookbook with a few personal variations and then moved to Moose::Manual since I am more of a learn by doing type. Attempting a few of the recipes with my variations first to get a flavor of Moose was the fastest way for me to get into the Moose world.

    Moose isn't just a cool object oriented framework, it also encourages (not requires) a certain object oriented style. Getting a handle on the style early on will allow you to make the intuitive leaps needed in learning to reach that point where you are using Moose and can extrapolate expected Moose behavior that you may not have learned yet. The ability to intuit the possible way Moose would solve a problem takes you a long way to find the answer for solving your problems. So then you will be able to identify when you have reach a point in your code where what you are attempting to do in Moose seems unnecessarily complicated. In most cases this means you have reached a point where it's time to go back to the documentation.

    Using this method allowed me to avoid trying to digest the whole Moose cookbook or manual at once. (Don't try to eat the whole Moose in one sitting.)

      Using the Moose::Cookbook along the Moose::Manual did help me get started with Moose, too. I did look at some presentations about Moose as well, but the Docs on CPAN are pretty good.
Reaped: Re: Migrate your perl project to Moose
by NodeReaper (Curate) on Oct 18, 2011 at 12:48 UTC
Re: Migrate your perl project to Moose
by aartist (Scribe) on Oct 20, 2011 at 14:08 UTC
    "I have to mirgrate it".
    You can of course learn Moose well from tutorials and cookbooks and slides as presented in other nodes,but also find out what are the benefits they are seeking from the migration and what is the timeframe they have. That will give you very good idea what you shoold look for. See which resources they can provide for the same, if they are familiar.

    Important thing is to start writing test for your existing code and make sure that it doesn't break with the new code. Start small with Moose and pave your way further.

    You can take help form online communities as well as IRC Channel #moose.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-07-26 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls