Skip to content

Create a 'use_overload' option #36

@rkleemann

Description

@rkleemann

Some objects overload numification or stringification, but don't have a TO_JSON method. It would be nice for those objects to be encoded without having to monkey patch a TO_JSON method for them. The one that pops to mind is URI, but there are others.

The following code would go somewhere in object_to_json, and should work for this.

if ( $use_overload && overload::Overloaded($obj) ) {
    if ( my $overload = overload::Method( $obj, '0+' )
                     || overload::Method( $obj, '""' ) )
    {
        return $self->value_to_json( $obj->$overload() );
    }
}

There would also be a sub to turn on/off the feature, and require overload; when it is enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions