in reply to Re: Remove a role from a Moose object
in thread Remove a role from a Moose object

The 'Configurable' role provides a bunch of methods that lets you modify some configuration files (ini and xml files). If a host is marked as read-only during the course of execution, then any attempt to configure that should result in an error.

Now, to answer you questions

a) the user checks  if ($host->configurable()) before using those methods. It is a syntactic sugar for has_role.

b) Configurable provide getters/setters and a whole bunch of other methods. The epxectation is that the object should not expose any of those methods.

c) What's the question ? I've no clue what '???' means.

And as to why I am doing this, this(making nodes readonly) is quite a common scenario when you are working with a set of network devices acting together. Call it a cluster of nodes if you want. I am just trying to see if there is a simple way of achieving what I want. Thanks

Replies are listed 'Best First'.
Re^3: Remove a role from a Moose object
by Monk::Thomas (Friar) on Nov 08, 2016 at 13:29 UTC

    I am pondering whether you are doing something extremely clever (and I fail to see the point) or whether you're just doing it wrong. The reason why I consider 'you are doing it wrong' is because all instances of a specific class are supposed to have the same interface.

    Typical approaches to solve your requirements would be:

    • define separate classes (e.g. 'host_Configurable' and 'Host_NonConfigurable'), where one provides setters and the other doesn't
    • always provide the setter-Methods (but silently ignore or violently die()/croak() if 'configurable()' is set to false)

    In your case I suggest the second approach since you indicated the readonly/readwrite status may change at some point.

      Thanks, I am going with the second approach for now. croaking/confessing when configurable is false. Thanks again.