jhthorsen / json-validator

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

Using with alternative frameworks (Catalyst In our case). #58

Closed akzhan closed 7 years ago

akzhan commented 7 years ago

I was bundled JSON::Validator into our Catalyst application but was LOL due to Mojolicious dependency.

Can I provide pull request with some updates like

etc.?

May need some extension/dependency injection points?

jhthorsen commented 7 years ago

I don't think this is doable. How will you fetch data from the web? The footprint need to be tiny, and using something like LWP will increase the footprint, compared to just using Mojolicious.

jhthorsen commented 7 years ago

What does "was LOL" mean? And what's the problem with depending on Mojolicious?

jhthorsen commented 7 years ago

How would you replace Mojo::JSON::Pointer with JSON::Pointer without breaking the interface?

akzhan commented 7 years ago

Just code piece (it passes all Mojo::JSON::Pointer tests):

package Panda::JSON::Pointer;

=head1 NAME

Panda::JSON::Pointer

=head1 DESCRIPTION

L<Mojo::JSON::Pointer> API compatible implementation
without L</Mojolicious> dependency.

=cut

use Panda::Perl;

use JSON::Pointer ();

sub new {
    my ( $class, $data ) = @_;

    $class = ref($class)  if ref $class;

    my $self = bless( { data => $data }, $class );

    return $self;
}

sub data {
    my $self = shift;

    return $self->{data}  unless scalar(@_);

    $self->{data} = $_[0];

    return $self;
}

{
    no strict 'refs';
    for my $method ( qw( get contains add remove replace set copy move test ) ) {
        *{$method} = sub {
            my $self = shift;

            return JSON::Pointer->$method( $self->{data}, @_ );
        };
    }
}

1;
akzhan commented 7 years ago

What does "was LOL" mean? And what's the problem with depending on Mojolicious?

Mojolicious is all-in-one framework. When I need only fetch/parse some data it's very strange to bundle Mojolicious with Catalyst/Dancer/Raisin etc.

jhthorsen commented 7 years ago

I would like your answer on my questions above.

FYI: this request have been closed before: https://github.com/jhthorsen/json-validator/issues/17

akzhan commented 7 years ago

Proposal: Allow to use JSON::Validator with injection points like JSON::Validator::URI, JSON::Validator::JSON, JSON::Validator::JSON::Pointer etc.

By default these implementations should be aliased to Mojo ones.

jhthorsen commented 7 years ago

That's not going to happen. I'm not adding extensive polyfill to JSON::Validator. Reason: Maintenance cost.

akzhan commented 7 years ago

OK