[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};
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
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?
[1]:http://codekata.pragprog.com/2007/01/kata_nine_back_.html
Sent from my mobile. Please excuse the brevity, spelling and punctuation.
http://www.twitter.com/purinkle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/northwestengland.pm/attachments/201=
01026/392c060c/attachment.htm
More information about the northwestengland.pm
mailing list