Created
June 25, 2012 09:36
-
-
Save eiro/2987642 to your computer and use it in GitHub Desktop.
debut de validateur MARC::MIR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use Modern::Perl; | |
use JSON; | |
use Plack::Request; | |
use MARC::MIR; | |
use Test::Builder; | |
sub run_test { | |
my ( $mir ) = @_; | |
my $tb = Test::Builder->create; | |
my $output; | |
$tb->output( \$output ); | |
my $id = record_id( $mir ) || ''; # see MARC::MIR documentation | |
$tb->ok( $id , "the record has an id" ); | |
$tb->ok( (9 == length $id), "good length for PPN" ); | |
$tb->ok( | |
( $id =~ m{ # AFAIK: a valid PPN can be | |
^ | |
(?: \d{9} # 9 digits | |
| \d{8}X ) # or 8 digits suffixed by X | |
$ | |
}g ) | |
, "good length for PPN" | |
); | |
$output; | |
} | |
sub { | |
# load MIR or exit 500 | |
my $mir = | |
decode_json | |
( Plack::Request->new(shift) | |
->body_parameters | |
->{mir} or return [500,[],["gimme some record"]] | |
) or return [500,[],["malformed json"]]; | |
# run test for mir and render TAP | |
[ 200 | |
, ['Content-Type' => 'text/plain'] | |
, [ run_test $mir ] | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment