Skip to content

External opt-in #9

@FCO

Description

@FCO

I was wondering, if I have a class that I want to use in 2 different places, but one is a external route and the other is an internal one. Then probably on both places I would want to "export" different attributes. Would have a way to do something like:

class Bla does JSON::Class[:externally-opt-in] {
   has $.private;
   has $.internal;
   has $.external;
}

my Bla $bla .= new: :1private, :2internal, :3external;



# on internal route:
$bla.to-json: :opt-in<internal external>; # { "internal": 2, "external": 3 }

# on external route:
$bla.to-json: :opt-in<external>; # { "external": 3 }

# and not specifying the attributes could die or return `null`



# or maybe even:

# on internal route:
my $internal-bla = $bla.opt-in: <internal external>;
$internal-bla.to-json; # { "internal": 2, "external": 3 }

# on external route:
my $external-bla = $bla.opt-in: <external>;
$external-bla.to-json; # { "external": 3 }



# or even:

# on internal route:
my %*JSON-Class-opt-in{Bla} = <internal external>;
$bla.to-json; # { "internal": 2, "external": 3 }

# on external route:
my %*JSON-Class-opt-in{Bla} = <external>;
$bla.to-json; # { "external": 3 }

I personally like the dynvar one because if I define it on my route, doesn't matter what I do with the object, it will never leak data...
Or something like that? If it already has something like that, I'm sorry.

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