Plack-App-RDF-Files

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

# Changelog for Plack-App-RDF-Files

0.12  2015-04-27 17:03:03 CEST
    - additional option 'normalize'

0.11  2014-12-12 12:02:37 CET
    - improved serialization, especially for Unicode characters
    - added 'app' function to simplify one-liners

0.10  2014-12-10 15:12:08 CET
    - fix non-streaming Unicode
    - migrated to Dist::Milla and Moo
    - major code cleanup and refactoring
    - add HTTP HEAD and conditional GET
    - fix feature index_property, remove include_index

0.02  2013-07-02
    - new method: files

0.01  2013-07-01
    - initial release

README  view on Meta::CPAN

    Core method of the PSGI application.

    The following PSGI environment variables are read and/or set by the
    application.

    rdf.uri
        The requested URI as string or URI object.

    rdf.iterator
        The RDF::Trine::Iterator that will be used for serializing, if
        "psgi.streaming" is set. One can use this variable to catch the RDF
        data in another post-processing middleware.

    rdf.files
        An hash of source filenames, each with the number of triples (on
        success) as property "size", an error message as "error" if parsing
        failed, and the timestamp of last modification as "mtime". "size"
        and "error" may not be given before parsing, if "rdf.iterator" is
        set.

    negotiate.format

lib/Plack/App/RDF/Files.pm  view on Meta::CPAN

    # add axiomatic triple to empty graphs
    if ($iterator->finished) {
        $iterator = RDF::Trine::Iterator::Graph->new( [ statement(
            iri($uri),
            iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
            iri('http://www.w3.org/2000/01/rdf-schema#Resource')
        ) ] );
    }

    # construct PSGI response
    if ( $env->{'psgi.streaming'} ) {
        $env->{'rdf.iterator'} = $iterator;
        return sub {
            my $responder = shift;
            my $body = $self->_serialize_body( $serializer, $iterator );       
            $responder->( [ 200, $headers->headers, $body ] );
        };
    } else {
        my $body = $self->_serialize_body( $serializer, $iterator );
        return [ 200, $headers->headers, $body ];
    }

lib/Plack/App/RDF/Files.pm  view on Meta::CPAN


=over 4

=item rdf.uri

The requested URI as string or L<URI> object.

=item rdf.iterator

The L<RDF::Trine::Iterator> that will be used for serializing, if
C<psgi.streaming> is set. One can use this variable to catch the RDF
data in another post-processing middleware.

=item rdf.files

An hash of source filenames, each with the number of triples (on success)
as property C<size>, an error message as C<error> if parsing failed, and
the timestamp of last modification as C<mtime>. C<size> and C<error> may
not be given before parsing, if C<rdf.iterator> is set.

=item negotiate.format

t/basic.t  view on Meta::CPAN

    foreach (qw(/ /rdf0 ../data/alice)) {
    	is $cb->(GET $_)->code, '404', "404 not ok: $_";
    }

	my $res = $cb->(GET "/alice", Accept => 'application/json'); 
	is $res->code, '200', '200 OK';
    is $res->header('Content-Type'), 'application/json';
    is_deeply (JSON->new->decode($res->decoded_content), $rdf_json, 'RDF/JSON');
};

# test non-streaming
my $env = GET("/alice")->to_psgi; 
$env->{'psgi.streaming'} = 0;
$env->{'negotiate.format'} = 'json';
#$env->{'rdf.uri'} = 'http://example.com/bob';
my $res = $app->call($env);
my $body = ref $res->[2] eq 'ARRAY' ? $res->[2]->[0] : $res->[2]->getline;
is_deeply( JSON->new->decode($body), $rdf_json, 'non-streaming, negotiate.format' );

done_testing;



( run in 0.248 second using v1.01-cache-2.11-cpan-4d50c553e7e )