Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hey thanks for the reply.

For instance, if I'm building a Car object, I'll probably want to declare an "Engine" object and then handle the delegation of that objects methods in the Car object.


package Car::Engine; use 5.010; use Moose; use strict; use warnings; has [qw(cylinder rpm fuel)] { is => 'rw', isa => 'Int', } sub get_rpm { my $self = shift; my $curr_rpm = $self->rpm / $self->cylinder; } package Car; use 5.010; use Moose; use strict; use warnings; has [qw(engine_cylinder engine_rpm engine_fuel)] => ( is => 'rw', isa => 'Int', ); has engine => ( is => 'rw', isa => 'Car::Engine', default => { Car::Engine->new( cylinder => $_[0]->engine_cylinder, rpm => $_[0]->engine_rpm, fuel => $_[0]->engine_rpm, ); }, handles => { get_rpm => 'get_rpm', } ); package main; use 5.010; use strict; use warnings; my $car = Car->new( engine_cylinder => '8', engine_rpm => '8000', engine_fuel => '1000', ); say $car->get_rpm;

(actually, the equation for rpms doesn't make any sense, but it was just to show that ->get_rpm is different than ->rpm)

In the real world I'm working on a library to manage VMs and I've created several objects to represent things like the Hypervisor Cluster and the VM (which represents all the attributes for the vm, the actual running vm is then represented by a different object which I'm trying to figure out how to handle).

I don't know what the correct term for "Car::Engine" would be in this case which is why I called it a "sub-object" in my previous comment.

I just seem to be using the pattern a lot which results is a lot of duplicate typing (or cut and paste) which got me to thinking maybe there's a better way to go about using objects in my primary (in this case "Car") object.

In reply to Re^2: [Moose] Critique request on my Moose design (anti?)pattern by three18ti
in thread [Moose] Critique request on my Moose design (anti?)pattern by three18ti

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2018-10-20 12:23 GMT
    Find Nodes?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...

      Results (117 votes). Check out past polls.