File Coverage

blib/lib/OpenGuides/RDF/Reader.pm
Criterion Covered Total %
statement 15 17 88.2
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 22 90.9


line stmt bran cond sub pod time code
1             package OpenGuides::RDF::Reader;
2 1     1   30146 use strict;
  1         3  
  1         48  
3              
4             BEGIN {
5 1     1   6 use Exporter ();
  1         2  
  1         27  
6 1     1   6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  1         7  
  1         149  
7 1     1   2 $VERSION = '0.05';
8 1         15 @ISA = qw(Exporter);
9 1         2 @EXPORT = qw(parse_rdf);
10 1         2 @EXPORT_OK = qw(parse_rdf);
11 1         19 %EXPORT_TAGS = (all => [qw(parse_rdf)]);
12             }
13              
14 1     1   427 use XML::Simple;
  0            
  0            
15              
16             sub parse_rdf {
17             my $xml = shift;
18              
19             my $rdf = XMLin( $xml,
20             ForceArray => [qw/foaf:based_near dc:subject/ ],
21             GroupTags => {'dc:source' => 'rdf:resource',
22             'foaf:homepage' => 'rdf:resource' },
23             #NumericEscape => 2,
24             );
25              
26             my $geo;
27             my $desc = $rdf->{'rdf:Description'};
28             if (ref $desc eq 'ARRAY') {
29             $geo = $desc->[1];
30             $desc = $desc->[0];
31             }
32             else {
33             $geo = $rdf->{'geo:SpatialThing'};
34             }
35            
36             my %descmap = (
37             username => 'dc:contributor',
38             changed => 'dc:date',
39             version => 'wiki:version',
40             source => 'dc:source',
41             );
42             my %geomap = (
43             country => 'country',
44             city => 'city',
45             address => 'address',
46             postcode => 'postalCode',
47             phone => 'phone',
48             fax => 'fax',
49             website => 'foaf:homepage',
50             opening_hours_text => 'chefmoz:Hours',
51             longitude => 'geo:long',
52             latitude => 'geo:lat',
53             category => 'dc:subject',
54             summary => 'dc:description',
55             );
56             my %out;
57             $out{$_} = $desc->{$descmap{$_}} for keys %descmap;
58             $out{$_} = $geo->{$geomap{$_}} for keys %geomap;
59             $out{locale} = [ map {$_->{'wn:Neighborhood'}{'foaf:name'}}
60             @{$geo->{'foaf:based_near'}} ] if exists $geo->{'foaf:based_near'};
61              
62             %out;
63             }
64              
65             =head1 NAME
66              
67             OpenGuides::RDF::Reader - Parse and return OpenGuides metadata from RDF
68              
69             =head1 SYNOPSIS
70              
71             use OpenGuides::RDF::Reader;
72             use WWW::Mechanize;
73             ...
74             my $agent = WWW::Mechanize->new;
75             $agent->get("http://fooville.openguides.org/?id=Red_Lion;format=rdf");
76             my %metadata = parse_rdf($agent->content);
77              
78              
79             =head1 DESCRIPTION
80              
81             The L software deliberately exposes data collected on the town wiki
82             sites, making it available to other websites as RDF / XML. This functionality is
83             provided by the module L supplied in the OpenGuides distribution.
84              
85             What OpenGuides::RDF::Reader does is the reverse process, i.e. take XML RDF data
86             and turn it back into a hash with keys comprising the metadata fields in OpenGuides.
87             The main use of this is for guide replication.
88              
89             =head2 parse_rdf
90              
91             This exported subroutine takes a string containing RDF and returns a list of
92             metadata key value pairs.
93              
94             =head1 BUGS
95              
96             Please report any bugs in this module using http://rt.cpan.org/ or posting to
97             bugs-openguides-rdf-reader (at) rt.cpan.org.
98              
99             =head1 SUPPORT
100              
101             For discussion of all matters relating to OpenGuides, there is a mailing list
102             http://openguides.org/mm/listinfo/openguides-dev.
103              
104             =head1 AUTHOR
105              
106             Ivor Williams
107             CPAN ID: IVORW
108            
109             ivorw-openguides (at) xemaps.com
110             http://openguides.org/
111              
112             =head1 COPYRIGHT
113              
114             This program is free software licensed under the...
115              
116             The General Public License (GPL)
117             Version 2, June 1991
118              
119             The full text of the license can be found in the
120             LICENSE file included with this module.
121              
122              
123             =head1 SEE ALSO
124              
125             L.
126              
127             =cut
128              
129              
130             1;
131             # The preceding line will help the module return a true value
132