develooper Front page | perl.moose | Postings from February 2015

Re: incomplete role consumption?

Thread Previous | Thread Next
From:
Ben Tilly
Date:
February 26, 2015 13:17
Subject:
Re: incomplete role consumption?
Message ID:
CANoac9Xjg6RJ9-uawHOnwXBUQ8FD8LAvZE-G_EzBZXL3Ma4chw@mail.gmail.com
I would suggest that you don't need to use Node and VM in the Cluster
class.  In order to use the Cluster class properly, someone will have
to pass in Node and VM objects, but it is their responsibility to make
sure that Node and VM are loaded.

That won't work smoothly if the Cluster class offers convenience
methods which generate Node and VM objects.  In that case you should
put requires inside of those convenience methods.  That way you
guarantee that those classes exist when you need them, and break the
circular dependencies while loading.

On Thu, Feb 26, 2015 at 12:33 AM, Daniel Hermann
<daniel-hermann@1und1.de> wrote:
> Hi Nick,
>
> On 02/25/2015 10:35 PM, Nick Perez wrote:
>>
>> You are correct in your  deduction. And this is not Moose specific.
>> Circular dependencies like in your example cause undefined behavior
>> in Perl. What I don't understand is why you need the TestGlue class
>> or the circular dependency at all. Can you please take a step back
>> and explain what it is you are trying to accomplish?
>>
>
> in my application, I have the following entities:
>
> Test1 == Node  (a host node)
> Test2 == Vm (a virtual host)
> TestRole == HostRole (common parts of Node and Vm, with sub load_host())
> TestGlue == Cluster  (a cluster of host nodes and virtual hosts)
>
> Node and Vm both consume the HostRole, which has a 'cluster' attribute.
> Therefore, HostRole uses Cluster.
>
> On the other hand, the Cluster class has some functionality that operates on
> Node and Vm objects, such as representing or manipulating
> all nodes and vms of the cluster. Therefore, it uses Node and Vm.
>
> I understand that the problems indicate that there is some fundamental
> class design flaw here.
>
> regards,
>
> Daniel
>
> --
> Daniel Hermann
>
> Operations Developer
> 1&1 Internet AG
>
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About