Taking another look at Moose

With large libraries in the Perl world it’s easy to be overwhelmed by all their features and not realise all the things they have to offer. The Moose library is a prime example. There are two things that I noticed relatively recently, that I had initially overlooked. Moose delegation and the moose-outdated tool.

Moose delegation can be read about here in the manual, Moose::Manual::Delegation. It allows you to have a property that you pass methods straight through to. Their example illustrates it simply,

 package Website;

  use Moose;

  has 'uri' => (
      is      => 'ro',
      isa     => 'URI',
      handles => [qw( host path )],

The new website object will have a host and a path method that get passed straight to the uri properties host and path methods. This makes that fairly common pattern really simple to implement, saving time on what is often useful but tedious code to write.

moose-outdated is a tool that ships with Moose to help you spot dependency problems. It’s particularly useful after a major upgrade of Moose when you can run it to report any other modules that now require an upgrade as a result. It’s their way of helping you avoid CPAN hell.

$ moose-outdated 

If you’re lucky you get no output like this. Otherwise simply upgrade the modules it complains about.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s