# AutoFnBind reference

AutoFnBind provides a scoped way of pushing and popping of the FnBindings on the FnReturns. The pushing happens when an AutoFnBind object is constructed, the popping when it is destroyed (or on an explicit clearing).

    $ab = AutoFnBind->new($ret1 => $binding1, ...);

Create an AutoFnBind object. The arguments consist of pairs of FnReturns and FnBindings to push on them. The pushing will happen in the constructor in the order specified, the popping in the destructor or

    clear()

method in the opposite order.

If any corruption of the call stack is detected at the popping time (i.e. the binding on the top of the stack is not the one that was pushed on it), this error will be detected. However since there is no way to report an error from a Perl destructor, this error message will be printed on stderr and the whole program will exit with the code 1. If you care about the ability to catch this error, use the method

    clear()

before destroying the AutoFnBind object.

    $ab->clear();

Pop the bindings, just as during the destruction, and discard the references to the FnReturn and FnBinding objects. After the clearing is done once, the destructor will not pop anything any more, and the repeated clearings will have no effect.

Any detected stack corruptions make this method confess. The popping will always go through the whole list of bindings, collecting the error reports along the way. At the end of the run it will make sure that it doesn't have any references to anything any more, and only then confess if any errors were found. This cleans up the things as much as possible and as much as can be handled, but the end result will still not be particularly clean: the returns that got their stacks corrupted will still have their stacks corrupted, and some very serious application-level cleaning will be needed to continue. Probably a better choice would be to destroy everything and restart from scratch. But at least it allows to get safely to this point of restarting from scratch.

    $res = $ab->same($ab2);

The usual check for two references referring to the same object.

AutoFnBind