File Coverage

blib/lib/SemanticWeb/OAI/ORE/Constant.pm
Criterion Covered Total %
statement 110 116 94.8
branch 3 6 50.0
condition n/a
subroutine 36 37 97.3
pod 2 2 100.0
total 151 161 93.7


line stmt bran cond sub pod time code
1             package SemanticWeb::OAI::ORE::Constant;
2              
3 8     8   140344 use warnings;
  8         20  
  8         338  
4 8     8   47 use strict;
  8         14  
  8         495  
5 8     8   48 use Carp;
  8         16  
  8         705  
6              
7             =head1 NAME
8              
9             SemanticWeb::OAI::ORE::Constant - Module providing constants used by OAI-ORE
10             Resource Map objects
11              
12             =cut
13              
14 8     8   64 use constant ORE_PREFIX => 'ore';
  8         14  
  8         987  
15 8     8   46 use constant ORE_NS => 'http://www.openarchives.org/ore/terms/';
  8         24  
  8         398  
16 8     8   42 use constant DC_PREFIX => 'dc';
  8         15  
  8         400  
17 8     8   42 use constant DC_NS => 'http://purl.org/dc/elements/1.1/';
  8         22  
  8         484  
18 8     8   43 use constant DCT_PREFIX => 'dcterms';
  8         27  
  8         378  
19 8     8   43 use constant DCT_NS => 'http://purl.org/dc/terms/';
  8         15  
  8         345  
20 8     8   77 use constant RDF_PREFIX => 'rdf';
  8         39  
  8         349  
21 8     8   39 use constant RDF_NS => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  8         66  
  8         424  
22 8     8   39 use constant FOAF_PREFIX => 'foaf';
  8         16  
  8         318  
23 8     8   38 use constant FOAF_NS => 'http://xmlns.com/foaf/0.1/';
  8         13  
  8         328  
24 8     8   43 use constant OWL_PREFIX => 'owl';
  8         15  
  8         372  
25 8     8   46 use constant OWL_NS => 'http://www.w3.org/2002/07/owl#';
  8         13  
  8         399  
26              
27 8     8   44 use constant RESOURCE_MAP => 'http://www.openarchives.org/ore/terms/ResourceMap';
  8         12  
  8         612  
28 8     8   41 use constant AGGREGATION => 'http://www.openarchives.org/ore/terms/Aggregation';
  8         24  
  8         349  
29 8     8   40 use constant DESCRIBES => 'http://www.openarchives.org/ore/terms/describes';
  8         13  
  8         377  
30 8     8   41 use constant AGGREGATES => 'http://www.openarchives.org/ore/terms/aggregates';
  8         14  
  8         423  
31 8     8   47 use constant AGGREGATED_BY => 'http://www.openarchives.org/ore/terms/isAggregatedBy';
  8         13  
  8         565  
32 8     8   44 use constant HAS_TYPE => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
  8         55  
  8         382  
33 8     8   42 use constant CREATOR => 'http://purl.org/dc/terms/creator';
  8         21  
  8         426  
34 8     8   49 use constant MODIFIED => 'http://purl.org/dc/terms/modified';
  8         14  
  8         601  
35 8     8   40 use constant RIGHTS => 'http://purl.org/dc/elements/1.1/rights';
  8         15  
  8         360  
36 8     8   42 use constant CREATED => 'http://purl.org/dc/terms/created';
  8         14  
  8         382  
37 8     8   59 use constant FOAF_NAME => 'http://xmlns.com/foaf/0.1/name';
  8         15  
  8         361  
38 8     8   39 use constant FOAF_MBOX => 'http://xmlns.com/foaf/0.1/mbox';
  8         13  
  8         335  
39              
40 8     8   39 use constant RESOURCE => 1;
  8         15  
  8         322  
41 8     8   40 use constant LITERAL => 2;
  8         13  
  8         375  
42              
43 8     8   40 use constant QUIET => 1;
  8         14  
  8         353  
44 8     8   41 use constant WARN => 2;
  8         101  
  8         572  
45 8     8   43 use constant FATAL => 3;
  8         15  
  8         360  
46 8     8   48 use constant RECKLESS => 99;
  8         15  
  8         418  
47 8     8   42 use constant ERROR_LEVEL => [ 'NO_ERROR', 'QUIET', 'WARN', 'FATAL' ]; #order must match, not values not constant
  8         16  
  8         412  
48              
49             =head2 EXPORTED CONSTANTS
50              
51             The following constants may be imported either individually or using
52             the tags show:
53              
54             ORE_PREFIX DC_PREFIX DCT_PREFIX RDF_PREFIX (tag: prefix)
55             ORE_NS DC_NS DCT_NS RDF_NS (tag: ns)
56             RESOURCE_MAP AGGREGATION (tag: entity)
57             DESCRIBES AGGREGATES AGGREGATED_BY HAS_TYPE CREATOR CREATED RIGHTS MODIFIED (tag: rel)
58             RESOURCE LITERAL (tag: internal)
59             QUIET WARN FATAL RECKLESS ERROR_LEVEL (tag: err)
60              
61             for example, to use MODIFIED and other relationships one might want
62             to import as:
63              
64             use SemanticWeb::OAI::ORE::Constant qw(:rel);
65             print "The uri for modified time is ".MODIFIED."\n";
66              
67             =cut
68              
69 8     8   50 use base qw(Exporter);
  8         16  
  8         7244  
70             our @EXPORT_OK = qw(
71             ORE_PREFIX DC_PREFIX DCT_PREFIX RDF_PREFIX FOAF_PREFIX OWL_PREFIX
72             ORE_NS DC_NS DCT_NS RDF_NS FOAF_NS OWL_NS
73             RESOURCE_MAP AGGREGATION
74             DESCRIBES AGGREGATES AGGREGATED_BY HAS_TYPE CREATOR CREATED RIGHTS MODIFIED FOAF_NAME FOAF_MBOX
75             RESOURCE LITERAL
76             QUIET WARN FATAL RECKLESS ERROR_LEVEL
77             namespace_and_name expand_qname
78             );
79             our %EXPORT_TAGS = (
80             'prefix' => [qw( ORE_PREFIX DC_PREFIX DCT_PREFIX RDF_PREFIX FOAF_PREFIX OWL_PREFIX )],
81             'ns' => [qw( ORE_NS DC_NS DCT_NS RDF_NS FOAF_NS OWL_NS )],
82             'entity' => [qw( RESOURCE_MAP AGGREGATION )],
83             'rel' => [qw( DESCRIBES AGGREGATES AGGREGATED_BY HAS_TYPE CREATOR CREATED RIGHTS MODIFIED FOAF_NAME FOAF_MBOX)],
84             'internal' => [qw( RESOURCE LITERAL )],
85             'err' => [qw( QUIET WARN FATAL RECKLESS ERROR_LEVEL )],
86             );
87              
88             # Add all tag (easy since tags above are non-overlapping)
89             $EXPORT_TAGS{all}=[];
90             push @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS;
91             push @{$EXPORT_TAGS{all}}, 'namespace_and_name', 'expand_qname';
92              
93             our %PREFIX_TO_NS = ( #parens needed to avoid perl quoting strings
94             ORE_PREFIX()=>ORE_NS, DC_PREFIX()=>DC_NS, DCT_PREFIX()=>DCT_NS,
95             RDF_PREFIX()=>RDF_NS, FOAF_PREFIX()=>FOAF_NS, OWL_PREFIX()=>OWL_NS );
96              
97             our %NS_TO_PREFIX = ( reverse %PREFIX_TO_NS );
98              
99              
100             =head2 EXPORTED SUBROUTINES
101              
102             =head3 namespace_and_name($element)
103              
104             FIXME - should probably change all the constants here to use
105             "Clarkian" notation for namespace and element name {ns}name.
106              
107             =cut
108              
109             sub namespace_and_name {
110 0     0 1 0 my ($element)=@_;
111 0         0 foreach my $ns (ORE_NS,DC_NS,DCT_NS,RDF_NS,FOAF_NS,OWL_NS) {
112 0 0       0 if ($element=~/^$ns(.+)$/) {
113 0         0 return($ns,$1);
114             }
115             }
116 0         0 carp "Failed to find ns for $element";
117 0         0 return('',$element);
118             }
119              
120              
121             =head3 expand_qname
122              
123             Will attempt to expand an input resource matching the qname syntax ([a-z]+:\w+)
124             to a full URI if the prefix is known. Otherwise string left unchanged. It should
125             be safe the call this expansion on something that it either a qname or a URI
126             because a URI will not match the pattern AND the prefixes defined here do
127             not correspond to URI schemes.
128              
129             See also L
130              
131             =cut
132              
133             sub expand_qname {
134 5     5 1 1356 my ($qname)=@_;
135 5 100       18 if ($qname=~/^([a-z]+):(\w+)$/) {
136 2 50       9 if (my $ns=$PREFIX_TO_NS{$1}) {
137 2         6 $qname="$ns$2";
138             }
139             }
140 5         18 return($qname);
141             }
142              
143             =head1 COPYRIGHT & LICENSE
144              
145             Copyright 2007-2010 Simeon Warner.
146              
147             This program is free software; you can redistribute it and/or modify it
148             under the same terms as Perl itself.
149              
150             =cut
151              
152             1;
153