Unfortunately, when it comes to objects with accessor methods, good practice forbids us to directly access the internal hash or array that stores the object state; so slices are no longer available, and every attribute of the object must be accessed in a separate call.

The present module comes the rescue : it exports a single subroutine mslice (for "method slice"), that takes an object and a collection of method names, and encapsulates a list of method calls, either to get a list of attributes, or to set them in a single list operation.

Takes an object reference, and a collection of method names, which are supposed to be getter/setter methods in the usual sense (i.e. we should be able to write my $val = $object->meth1() for getting a value, and $object->meth1($new_val) for setting a value within that object).

If mslice is called in an rvalue context, it will return a list of values obtained by calling the methods as getter accessors (i.e. without any argument).

If mslice is called in an lvalue assign context, it will call each accessor in the method list, with a single argument corresponding to the item in the corresponding position within the list on the right-hand side. Notice that the mslice call should be enclosed in parenthesis so that it is in list context, not in scalar context.

Unfortunately mslice cannot be called in a lvalue, non-assign context. This is typically the case when using it as an argument to another subroutine (because that other subroutine receives aliases to its arguments in @_, and might alter those aliases). So for such situations we have to force an rvalue context by writing