File Coverage

blib/lib/Types/Namespace.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Types::Namespace;
2 6     6   387359 use strict;
  6         23  
  6         166  
3 6     6   25 use warnings;
  6         12  
  6         253  
4              
5 6     6   467 use Type::Library -base, -declare => qw( Uri Iri Namespace NamespaceMap );
  6         21158  
  6         54  
6 6     6   5490 use Types::Standard qw( HashRef InstanceOf );
  6         40923  
  6         37  
7 6     6   6534 use Types::URI qw();
  6         504442  
  6         1411  
8              
9             my $AtteanIRI = InstanceOf['Attean::IRI'];
10             my $TrineNS = InstanceOf['RDF::Trine::Namespace'];
11             my $TrineNSMap = InstanceOf['RDF::Trine::NamespaceMap'];
12             my $TrineNode = InstanceOf['RDF::Trine::Node::Resource'];
13              
14             our $VERSION = '1.10';
15              
16             =head1 NAME
17              
18             Types::Namespace - type constraints for dealing with namespaces
19              
20             =head1 SYNOPSIS
21              
22             package Namespace::Counter {
23             use Moo; # or Moose
24             use Types::Namespace qw( Namespace );
25              
26             has ns => (
27             is => "ro",
28             isa => Namespace,
29             required => 1,
30             );
31              
32             sub count_uses_in_document { ... }
33             }
34              
35             =head1 DESCRIPTION
36              
37             Types::Namespace is a type constraint library suitable for use with
38             L<Moo>/L<Moose> attributes, L<Kavorka> sub signatures, and so
39             forth. It builds on L<Types::URI>.
40              
41             =head1 TYPES
42              
43             =over
44              
45             =item C<< Namespace >>
46              
47             A class type for L<URI::Namespace>.
48              
49             Can coerce from L<URI>, L<IRI>, L<Path::Tiny>, L<Attean::IRI>,
50             L<RDF::Trine::Namespace>, L<RDF::Trine::Node::Resource> and strings.
51              
52             =item C<< NamespaceMap >>
53              
54             A class type for L<URI::NamespaceMap>.
55              
56             Can coerce from a hashref of C<< prefix => URI >> pairs and from
57             L<RDF::Trine::NamespaceMap>.
58              
59             =item C<< Uri >>, C<< Iri >>
60              
61             These namespaces are re-exported from L<Types::URI>, but with an
62             additional coercion from the C<< Namespace >> type.
63              
64             =back
65              
66             =head1 FURTHER DETAILS
67              
68             See L<URI::NamespaceMap> for further details about authors, license, etc.
69              
70             =cut
71              
72             __PACKAGE__->add_type(
73             name => Uri,
74             parent => Types::URI::Uri,
75             coercion => [
76             @{ Types::URI::Uri->coercion->type_coercion_map },
77             InstanceOf['URI::Namespace'] ,=> q{ $_->uri() },
78             ],
79             );
80              
81             __PACKAGE__->add_type(
82             name => Iri,
83             parent => Types::URI::Iri,
84             coercion => [
85             @{ Types::URI::Iri->coercion->type_coercion_map },
86             InstanceOf['URI::Namespace'] ,=> q{ $_->iri() },
87             ],
88             );
89              
90             __PACKAGE__->add_type(
91             name => Namespace,
92             parent => InstanceOf['URI::Namespace'],
93             coercion => [
94             Iri->coercibles ,=> q{ "URI::Namespace"->new($_) },
95             $AtteanIRI ,=> q{ "URI::Namespace"->new($_->as_string) },
96             $TrineNode ,=> q{ "URI::Namespace"->new($_->as_string) },
97             $TrineNS ,=> q{ "URI::Namespace"->new($_->as_string) },
98             ],
99             );
100              
101             __PACKAGE__->add_type(
102             name => NamespaceMap,
103             parent => InstanceOf['URI::NamespaceMap'],
104             coercion => [
105             HashRef ,=> q{ "URI::NamespaceMap"->new(namespace_map => $_) },
106             $TrineNSMap ,=> q{ do { my $map = $_; my %hash = map { $_ => $map->namespace_uri($_)->uri_value } $map->list_prefixes ; "URI::NamespaceMap"->new(namespace_map => \%hash) } }
107             ],
108             );
109              
110             require URI::Namespace;
111             require URI::NamespaceMap;
112              
113             1;