jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

some questions #167

Closed sklukin closed 5 years ago

sklukin commented 5 years ago

my $new_joi = $joi->extend($joi); Will extend $joi with the definitions in $joi and return a new object.

It is not clear which will be expanded - $jio or $jio ))

my $new_joi = $joi->extend($joi_new); I think that $joi_new added to $joi and $joi_new remained the same as before

I added the second to the first, and the second remained the same. Not this way?

rebless $self in extend. Why?

jhthorsen commented 5 years ago

It creates a new object, since extend() should not mutate the original joi object, aka $self.

Your first example doesn’t make any sense. Why would you extend a joi object with itself?

I’m not sure what you’re asking about to be honest...

sklukin commented 5 years ago

Your first example doesn’t make any sense. Why would you extend a joi object with itself? First example from doc https://metacpan.org/pod/JSON::Validator::Joi#extend

Ok Why mutate second $joi?

#!/usr/bin/env perl

use Mojo::Base -strict;
use JSON::Validator 'joi';
use DDP;

my $joi1 = joi->object->props(
    name => joi->string->required,
    age  => joi->string->required,
);

my $joi2 = joi->object->props(
    friends => joi->object->props(
        jon => joi->object->props(
            name => joi->string->required,
            age  => joi->string->required,
        ),
        anna => joi->object->props(
            name => joi->string->required,
            age  => joi->string->required,
        ),
    )
);

my $joi3 = $joi1->extend( $joi2 );
p $joi2;

Now $joi2 contains both $joi1 and $joi2. Why?

I think the second one also does not need to be muetate

The third is the merge of the first and second, but they do not mutate. No?

jhthorsen commented 5 years ago

That is indeed a bug. I've pushed a new commit to master now, and will make a new release later today or tomorrow, depending on your feedback.

Thanks for letting me know 👍

sklukin commented 5 years ago

I am glad to help

sklukin commented 5 years ago

Its ok. Make release, please