Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Moose class design for game

by tobyink (Canon)
on Sep 06, 2013 at 06:52 UTC ( [id://1052656]=note: print w/replies, xml ) Need Help??


in reply to Moose class design for game

Keep the common BadGuy stuff in a role, and compose that into different subclasses for the client and server.

package TheGame::Roles::BadGuy { use Moose::Role; has 'name' => (is => 'ro', isa => 'Str'); requires 'health'; } package TheGame::Client::BadGuy { use Moose; with 'TheGame::Roles::BadGuy'; sub health { my $self = shift; my $health = do { ... }; return int($health/10)*10; # round to nearest 10% } } package TheGame::Server::BadGuy { use Moose; with 'TheGame::Roles::BadGuy'; has health => (is => 'rw', isa => 'Num'); has inventory => (is => 'rw', isa => 'ArrayRef'); }
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: Moose class design for game
by wanna_code_perl (Friar) on Sep 06, 2013 at 10:00 UTC

    That seems to fit rather neatly. Thanks! When I got my degree, roles were something you dressed up for as part of the fine arts elective, not a software design pattern. Thanks for shining a light on another thing I clearly need to do some updated reading on. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1052656]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found