APISchema

 view release on metacpan or  search on metacpan

lib/APISchema/DSL.pm  view on Meta::CPAN

sub process (&) {
    my $dsl = shift;

    my $schema = APISchema::Schema->new;

    local $_directive->{include} = sub {
        my ($file) = @_;
        -r $_[0] or Carp::croak(sprintf 'No such file: %s', $file);
        my $content = file($file)->slurp;
        my $with_utf8 = "use utf8;\n" . $content;
        eval $with_utf8;
        Carp::croak($@) if $@;
    };
    local $_directive->{title} = sub {
        $schema->title(@_);
    };
    local $_directive->{description} = sub {
        $schema->description(@_);
    };

    my @filters;

lib/APISchema/Validator.pm  view on Meta::CPAN

        content_type => $content_type,
    } )
        unless APISchema::Validator::Decoder->new->can($method);

    return ($method, undef);
}

sub _validate {
    my ($validator_class, $decode, $target, $spec) = @_;

    my $obj = eval { APISchema::Validator::Decoder->new->$decode($target) };
    return { message => "Failed to parse $decode" } if $@;

    my $validator = $validator_class->new($spec->definition);
    my ($valid, $err) = $validator->validate($obj);

    return {
        attribute => $err->attribute,
        position  => $err->position,
        expected  => $err->expected,
        actual    => $err->actual,

t/test.pm  view on Meta::CPAN


        use parent qw(Test::Class);
        use Test::More;
        use Test::Fatal qw(lives_ok dies_ok exception);
        use Test::Deep;
        use Test::Deep::JSON;

        END { $package->runtests }
    ];

    eval $code;
    die $@ if $@;
}

1;



( run in 1.819 second using v1.01-cache-2.11-cpan-98e64b0badf )