[northwestengland.pm] Refactoring a Moose Class

Robert Whittaker cyclistsdismount at gmail.com
Tue Oct 26 12:07:43 GMT 2010

I am practising [Kata Nine: Back to the CheckOut][1] in Perl whilst also
trying to use Moose for the first time.

So far, I've created the following class:

    package Checkout;

    # $Id$

    use strict;
    use warnings;

    our $VERSION =3D '0.01 <x-apple-data-detectors://0>';

    use Moose;
    use Readonly;

    Readonly::Scalar our $PRICE_OF_A =3D> 50;

    sub price {
        my ( $self, $items ) =3D @_;

        if ( defined $items ) {
            $self->{price} =3D 0;

            if ( $items eq 'A' ) {
                $self->{price} =3D $PRICE_OF_A;

        return $self->{price};


    no Moose;


The whole `price` method doesn't feel very Moose-ish and I feel like this
could be refactored further.

Does anyone have any input on how this could be improved?


Sent from my mobile. Please excuse the brevity, spelling and punctuation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/northwestengland.pm/attachments/201=

More information about the northwestengland.pm mailing list