RDF/Trine/Namespace.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 100% 67 / 67 CC 5 SCAR 4.6
CC
5
Cov
100%
_install_namespaces
3.0
import
2.0
uri
2.0
CRAP 1.6
« RDF/Trine/Node/Variable.pm ↑ Summary RDF/Trine/Model/Union.pm »
1 # RDF::Trine::Namespace
2 # -----------------------------------------------------------------------------
3  
4  
5 =head1 NAME
6  
7 RDF::Trine::Namespace - Abbreviated syntax for constructing RDF node objects
8  
9 =head1 VERSION
10  
11 This document describes RDF::Trine::Namespace version 1.019
12  
13 =head1 SYNOPSIS
14  
15 use RDF::Trine::Namespace qw(rdf);
16 my $foaf = RDF::Trine::Namespace->new( 'http://xmlns.com/foaf/0.1/' );
17 my $pred = $foaf->name;
18 my $type = $rdf->type;
19 print $pred->as_string; # '[http://xmlns.com/foaf/0.1/name]'
20  
21 =head1 DESCRIPTION
22  
23 This module provides an abbreviated syntax for creating RDF::Trine::Node objects
24 for URIs sharing common namespaces. The module provides a constructor for creating
25 namespace objects which may be used for constructing Node objects. Calling any
26 method (other than 'import', 'new', 'uri' or 'AUTOLOAD') on the namespace object
27 will return a RDF::Trine::Node object representing the URI of the method name
28 appended to the namespace.
29  
30 =head1 METHODS
31  
32 =over 4
33  
34 =cut
35  
36 package RDF::Trine::Namespace;
37  
38 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 ▶use base qw(XML::Namespace);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 ######################################################################
44  
45 68 our ($VERSION);
46 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
47 68 $VERSION = '1.019';
48 }
49  
50 ######################################################################
51  
52  
53 68 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 68 ▶use RDF::Trine::Node::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 68 ▶use XML::CommonNS 0.04 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 300 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
58 300 my $class = shift;
59 300 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 156 144 300
60 156 $class->_install_namespaces( 1, @_ );
61 }
62 }
63  
64 156 ▶sub _install_namespaces {
Subroutine _install_namespaces: called CC=3 SCAR=11.0
65 156 my $class = shift;
66 156 my $level = shift;
67 156 my $pkg = caller( $level );
68 156 foreach my $name (@_) {
69 166 ▶ my $uri = (uc($name) eq 'XSD')
Branch: 1 branch
BranchTrueFalseTotal
uc $name eq 'XSD' ? : 12 154 166
70 ? XML::NamespaceFactory->new('http://www.w3.org/2001/XMLSchema#')
71 : XML::CommonNS->uri( uc($name) );
72 166 my $ns = $class->new( "$uri" );
73 68 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
74 166 *{ "${pkg}::${name}" } = \$ns;
75 }
76 }
77  
78 =item C<uri>
79  
80 Returns the URI node object for the namespace, with an optional path argument
81 added to the end of it.
82  
83 =cut
84  
85 8600 ▶sub uri {
Subroutine uri: called CC=2 SCAR=6.9
Pod documented
86 8600 my $self = shift;
87 8600 my $local = shift;
88 8600 ▶ unless (defined($local)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $local) 31 8569 8600
89 31 $local = '';
90 }
91
92 # we should just call $self->SUPER::uri($local) here, but there's a bug in
93 # XML::Namespace 0.2 that assumes $local eq '' if $local is defined but false (e.g. '0')
94 8600 my $uri = $self->SUPER::uri() . $local;
95 8600 return RDF::Trine::Node::Resource->new( $uri );
96 }
97  
98 =item C<< uri_value >>
99  
100 Returns the URI/IRI value of this namespace.
101  
102 =cut
103  
104 9 ▶sub uri_value {
Subroutine uri_value: called CC=1 SCAR=0.0
Pod documented
105 9 my $self = shift;
106 9 return $self->uri();
107 }
108  
109 68 1; # Magic true value required at end of module
110 __END__
« RDF/Trine/Node/Variable.pm ↑ Summary RDF/Trine/Model/Union.pm »