Theclasses (packages) into which the native types are boxed are fully configurable. By default, a method invoked on a non-object value is assumed to be defined in a class whose name corresponds to the ref() type of that value - or SCALAR if the value is a non-reference.
Multiple use autobox statements can appear in the same scope. These are merged both "horizontally" (i.e. multiple classes can be associated with a particular type) and "vertically" (i.e. multiple classes can be associated with multiple types).
Methods are called on native types by means of the arrow operator. As with regular objects, the right hand side of the operator can either be a bare method name or a variable containing a method name or subroutine reference. Thus the following are all valid:
The DEFAULT option specifies bindings for any of the four default types (SCALAR, ARRAY, HASH and CODE) not supplied in the use autobox statement. As with the other options, the value corresponding to the DEFAULT key can be a class name, a namespace, or a reference to an array containing one or more class names and/or namespaces.
DEBUG allows the autobox bindings for the current scope to be inspected, either by dumping them to the console or passing them to a callback function. This allows the computed bindings to be seen in "longhand".
This method sets up autobox bindings for the current lexical scope. It can be used to implement autobox extensions i.e. lexically-scoped modules that provide autobox bindings for one or more native types without requiring calling code to use autobox.
This sub returns the type of its argument within autobox (which is essentially longhand for the type names used within perl). This value is used by autobox to associate a method invocant with its designated classes e.g.
Perl's special-casing for the print BLOCK ... syntax (see perlsub) means that print expression() ... (where the curly brackets denote an anonymous HASH ref) may require some further disambiguation:
Operator overloading via the overload pragma doesn't (automatically) work. autobox works by lexically overriding the arrow operator. It doesn't bless native types into objects, so overloading - or any other kind of "magic" which depends on values being blessed - doesn't apply.
3a8082e126