[northwestengland.pm] Refactoring a Moose Class
Ian Norton
i.d.norton at gmail.com
Tue Oct 26 14:22:56 GMT 2010
Hi Robert,
On 26 October 2010 13:07, Robert Whittaker <cyclistsdismount at gmail.com> wrote:
> 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:
http://paste.scsys.co.uk/54214
'use Moose;' automatically pulls in 'use strict; use warnings;', so
you could save a couple of lines there... ;)
> The whole `price` method doesn't feel very Moose-ish and I feel like this
> could be refactored further.
No, you're right. Don't like the object abstraction though. I think
I'd opt for something along the lines of an object for the basket and
then objects with the items. As for the multibuy discount, not sure
:)
Seems like something that could reasonably be subtracted at the end of
the transaction though.
> Does anyone have any input on how this could be improved?
http://paste.scsys.co.uk/54215
I'd guess there should be a checkout function in Basket to total
things up, which is likely where the code for discounts should go.
That said, my attempt could be random, but something like that... :)
Regards, Ian
More information about the northwestengland.pm
mailing list