| 1 | package SemanticWeb::OAI::ORE::Constant; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 9 | ▶ | use constant ORE_PREFIX => 'ore'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 9 | ▶ | use constant ORE_NS => 'http://www.openarchives.org/ore/terms/'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 9 | ▶ | use constant DC_PREFIX => 'dc'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 9 | ▶ | use constant DC_NS => 'http://purl.org/dc/elements/1.1/'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 9 | ▶ | use constant DCT_PREFIX => 'dcterms'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 9 | ▶ | use constant DCT_NS => 'http://purl.org/dc/terms/'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 9 | ▶ | use constant RDF_PREFIX => 'rdf'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 9 | ▶ | use constant RDF_NS => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 9 | ▶ | use constant FOAF_PREFIX => 'foaf'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 9 | ▶ | use constant FOAF_NS => 'http://xmlns.com/foaf/0.1/'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 9 | ▶ | use constant OWL_PREFIX => 'owl'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 9 | ▶ | use constant OWL_NS => 'http://www.w3.org/2002/07/owl#'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 9 | ▶ | use constant RESOURCE_MAP => 'http://www.openarchives.org/ore/terms/ResourceMap'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 9 | ▶ | use constant AGGREGATION => 'http://www.openarchives.org/ore/terms/Aggregation'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 9 | ▶ | use constant DESCRIBES => 'http://www.openarchives.org/ore/terms/describes'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 9 | ▶ | use constant AGGREGATES => 'http://www.openarchives.org/ore/terms/aggregates'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 9 | ▶ | use constant AGGREGATED_BY => 'http://www.openarchives.org/ore/terms/isAggregatedBy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 9 | ▶ | use constant HAS_TYPE => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 9 | ▶ | use constant CREATOR => 'http://purl.org/dc/terms/creator'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 9 | ▶ | use constant MODIFIED => 'http://purl.org/dc/terms/modified'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 9 | ▶ | use constant RIGHTS => 'http://purl.org/dc/elements/1.1/rights'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 9 | ▶ | use constant CREATED => 'http://purl.org/dc/terms/created'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 9 | ▶ | use constant FOAF_NAME => 'http://xmlns.com/foaf/0.1/name'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 9 | ▶ | use constant FOAF_MBOX => 'http://xmlns.com/foaf/0.1/mbox'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 9 | ▶ | use constant RESOURCE => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 9 | ▶ | use constant LITERAL => 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 9 | ▶ | use constant QUIET => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 9 | ▶ | use constant WARN => 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 9 | ▶ | use constant FATAL => 3; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 9 | ▶ | use constant RECKLESS => 99; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 9 | ▶ | use constant ERROR_LEVEL => [ 'NO_ERROR', 'QUIET', 'WARN', 'FATAL' ]; #order must match, not values not constant | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 9 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 9 | 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 | 9 | 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 | 9 | $EXPORT_TAGS{all}=[]; | |||||||||
| 90 | 9 | push @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS; | |||||||||
| 91 | 9 | push @{$EXPORT_TAGS{all}}, 'namespace_and_name', 'expand_qname'; | |||||||||
| 92 | |||||||||||
| 93 | 9 | 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 | 9 | 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 | 0 | ▶ | sub namespace_and_name { | ||||||||
|
Subroutine
namespace_and_name: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 110 | 0 | my ($element)=@_; | |||||||||
| 111 | 0 | foreach my $ns (ORE_NS,DC_NS,DCT_NS,RDF_NS,FOAF_NS,OWL_NS) { | |||||||||
| 112 | 0 | ▶ | if ($element=~/^$ns(.+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | return($ns,$1); | |||||||||
| 114 | } | ||||||||||
| 115 | } | ||||||||||
| 116 | 0 | carp "Failed to find ns for $element"; | |||||||||
| 117 | 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<http://www.w3.org/TR/REC-xml-names/#NT-QName> | ||||||||||
| 130 | |||||||||||
| 131 | =cut | ||||||||||
| 132 | |||||||||||
| 133 | 11 | ▶ | sub expand_qname { | ||||||||
|
Subroutine
expand_qname: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 134 | 11 | my ($qname)=@_; | |||||||||
| 135 | 11 | ▶ | if ($qname=~/^([a-z]+):(\w+)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 2 | ▶ | if (my $ns=$PREFIX_TO_NS{$1}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 2 | $qname="$ns$2"; | |||||||||
| 138 | } | ||||||||||
| 139 | } | ||||||||||
| 140 | 11 | 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 | 9 | 1; | |||||||||
| 153 | |||||||||||