| 1 | |||||||||||
| 2 | package Catalyst::View::RDF; | ||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | extends 'Catalyst::View'; | |||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use RDF::Simple::Serialiser; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: RDF view for your data | ||||||||||
| 10 | 2 | our $VERSION = '0.01'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | 2 | has stash_key => ( | |||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | isa => 'Str', | ||||||||||
| 15 | lazy => 1, | ||||||||||
| 16 | default => 'triples' | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 2 | has nodeid_prefix => ( | |||||||||
| 20 | is => 'rw', | ||||||||||
| 21 | isa => 'Str', | ||||||||||
| 22 | lazy => 1, | ||||||||||
| 23 | default => 'a:' | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | has nss => ( | ||||||||||
| 27 | is => 'rw', | ||||||||||
| 28 | isa => 'HashRef', | ||||||||||
| 29 | lazy => '1', | ||||||||||
| 30 | predicate => 'has_nss', | ||||||||||
| 31 | 0 | ▶ | default => sub { {} } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 2 | ); | |||||||||
| 33 | |||||||||||
| 34 | 2 | has encoding => ( | |||||||||
| 35 | is => 'rw', | ||||||||||
| 36 | isa => 'Str', | ||||||||||
| 37 | lazy => 1, | ||||||||||
| 38 | default => 'utf-8' | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 1 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 42 | 1 | my ( $self, $c ) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 1 | my $ser = | |||||||||
| 45 | RDF::Simple::Serialiser->new( nodeid_prefix => $self->nodeid_prefix ); | ||||||||||
| 46 | |||||||||||
| 47 | 1 | ▶ | $ser->addns( $self->nss ) if $self->has_nss; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | 1 | my $triples = $c->stash->{ $self->stash_key }; | |||||||||
| 50 | 1 | my $rdf = $ser->serialise(@$triples); | |||||||||
| 51 | 1 | my $encoding = $self->encoding; | |||||||||
| 52 | |||||||||||
| 53 | 1 | $c->res->content_type("application/rdf; charset=$encoding"); | |||||||||
| 54 | 1 | $c->res->output($rdf); | |||||||||
| 55 | } | ||||||||||
| 56 | 2 | 1; | |||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | =pod | ||||||||||
| 60 | |||||||||||
| 61 | =head1 NAME | ||||||||||
| 62 | |||||||||||
| 63 | Catalyst::View::RDF - RDF view for your data | ||||||||||
| 64 | |||||||||||
| 65 | =head1 VERSION | ||||||||||
| 66 | |||||||||||
| 67 | version 0.01 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | # lib/MyApp/View/RDF.pm | ||||||||||
| 72 | package lib::MyApp::View::RDF; | ||||||||||
| 73 | use base qw( Catalyst::View::RDF ); | ||||||||||
| 74 | 1; | ||||||||||
| 75 | |||||||||||
| 76 | # configure in lib/MyApp.pm | ||||||||||
| 77 | MyApp->config({ | ||||||||||
| 78 | ... | ||||||||||
| 79 | 'View::RDF' => { | ||||||||||
| 80 | nodeid_prefix => 'a:', | ||||||||||
| 81 | nss => { foaf => 'http://xmlns.com/foaf/0.1/' }, | ||||||||||
| 82 | enconding => 'utf-8', | ||||||||||
| 83 | }, | ||||||||||
| 84 | |||||||||||
| 85 | }); | ||||||||||
| 86 | |||||||||||
| 87 | sub foaf : Local { | ||||||||||
| 88 | my ( $self, $c ) = @_; | ||||||||||
| 89 | my @triples = ( | ||||||||||
| 90 | ['http://example.com/url#', 'dc:creator', 'zool@example.com'], | ||||||||||
| 91 | ['http://example.com/url#', 'foaf:Topic', '_id:1234'], | ||||||||||
| 92 | ['_id:1234','http://www.w3.org/2003/01/geo/wgs84_pos#lat','51.334422'], | ||||||||||
| 93 | [$node1, 'foaf:name', 'Jo Walsh'], | ||||||||||
| 94 | [$node1, 'foaf:knows', $node2], | ||||||||||
| 95 | [$node2, 'foaf:name', 'Robin Berjon'], | ||||||||||
| 96 | [$node1, 'rdf:type', 'foaf:Person'], | ||||||||||
| 97 | [$node2, 'rdf:type','http://xmlns.com/foaf/0.1/Person'] | ||||||||||
| 98 | [$node2, 'foaf:url', \'http://server.com/NOT/an/rdf/uri.html'], | ||||||||||
| 99 | ); | ||||||||||
| 100 | $c->stash->{triples} = \@triples; | ||||||||||
| 101 | $c->forward('View::RDF'); | ||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | =head1 DESCRIPTION | ||||||||||
| 105 | |||||||||||
| 106 | Catalyst::View::RDF is a Catalyst View handler that returns stash | ||||||||||
| 107 | data in RDF format, based on L<RDF::Simple::Serialiser>. | ||||||||||
| 108 | |||||||||||
| 109 | =head1 AUTHOR | ||||||||||
| 110 | |||||||||||
| 111 | Thiago Rondon <thiago@aware.com.br> | ||||||||||
| 112 | |||||||||||
| 113 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 114 | |||||||||||
| 115 | This software is copyright (c) 2011 by Thiago Rondon. | ||||||||||
| 116 | |||||||||||
| 117 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 118 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 119 | |||||||||||
| 120 | =cut | ||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | __END__ | ||||||||||
| 124 | |||||||||||
| 125 | |||||||||||