purinkle_2 has asked for the wisdom of the Perl Monks concerning the following question:
I am practising Kata Nine: Back to the CheckOut 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 = '0.01'; use Moose; use Readonly; Readonly::Scalar our $PRICE_OF_A => 50; sub price { my ( $self, $items ) = @_; if ( defined $items ) { $self->{price} = 0; if ( $items eq 'A' ) { $self->{price} = $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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Refactoring a Moose Class
by TomDLux (Vicar) on Oct 26, 2010 at 15:52 UTC | |
|
Re: Refactoring a Moose Class
by Anonymous Monk on Oct 26, 2010 at 13:08 UTC |