jhthorsen / net-isc-dhcpd

Perl module that interacts with ISC DHCPd
http://search.cpan.org/perldoc?Net::ISC::DHCPd
11 stars 6 forks source link

Added test for generating failoverpeer config from code #23

Closed operatorofhell closed 8 years ago

operatorofhell commented 8 years ago

Here is a test regarding the Issue https://github.com/jhthorsen/net-isc-dhcpd/issues/21. I hope it clarifies what I want to do.

rfdrake commented 8 years ago

It looks like there might be two or three Moosey ways to fix this. I'm not sure if either are actually correct but so far the one I've tried does not seem to work so maybe option 2 would be better.

problem

The problem is that _order is not being set when we create a FailoverPeer with new(). In order to work around this we can

option 1

make a BUILD sub (pretty straightforward but seems yucky)

option 2

make a builder for _order that sets order variables based on if $self-> exists. Something like:

sub _build_order {
    my $self = shift;
    map { defined($self->$_) ? $_ : undef } keys %{$self->arguments};
}

Although this doesn't work because when _order calls it's builder apparently arguments hasn't been built yet.

option 3 (the one I'm committing for testing)

set a trigger in the has clause for all the variables that calls a sub to push their name into _order. This seems clean. It means we can also remove the push from the slurp part because this takes care of it for us.

Of course, it's never that simple..

http://stackoverflow.com/questions/22306330/moose-trigger-caller

So we picked up a new dep but I think this should fix it properly.