Skip to content

A proposed API to interact with fields inside instances #63

@leonerd

Description

@leonerd

While respecting that by default, fields of classes are in some sense "private" to that particular class, it is nevertheless inevitable that special-purpose pieces of perl code will want to "gut-wrench", and reach inside of instances to inspect or manipulate the data in the fields contained therein. In particular, see #62.

The moment we add some sort of MOP API (e.g. see the API shape suggested by Object::Pad::MOP::Class et.al.) it becomes possible to write functions to do justabout all of this. Therefore it makes sense to think about a standard set to be provided upfront.

Here is my suggestion:

A symmetric pair of functions that explode a given object instance into some lower-level representation of its fields, and one that reconstructs a new object based on that representation:

@repr = builtin::explode_object($obj);

$obj = builtin::make_object(@repr);

Here, $obj contains an object instance, and the @repr list contains some representation of the fields and the values they contain. I don't yet have a firm feel for exactly what shape that should be, but it should primarily be composed of plain strings, and plain scalars directly taken from fields. It might additionally contain extra structure in terms of hash or array references.

I have various thoughts on how that ought to look, but I'll expand on that in later messages. Point being: it should be possible to recuse down that to find more simple things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions