File Coverage

blib/lib/Types/URI.pm
Criterion Covered Total %
statement 36 36 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod n/a
total 48 48 100.0


line stmt bran cond sub pod time code
1 3     3   1118125 use 5.008;
  3         12  
  3         95  
2 3     3   14 use strict;
  3         4  
  3         90  
3 3     3   14 use warnings;
  3         11  
  3         172  
4              
5             package Types::URI;
6              
7             our $AUTHORITY = 'cpan:TOBYINK';
8             our $VERSION = '0.003';
9              
10 3     3   5018 use URI;
  3         18788  
  3         127  
11 3     3   4280 use URI::file;
  3         20632  
  3         96  
12 3     3   2565 use URI::data;
  3         8080  
  3         81  
13 3     3   2470 use URI::WithBase;
  3         2700  
  3         75  
14 3     3   2791 use URI::FromHash;
  3         34497  
  3         197  
15              
16 3     3   8758 use Type::Library -base, -declare => qw( Uri FileUri DataUri );
  3         99322  
  3         88  
17              
18 3     3   5464 use Types::Path::Tiny qw( Path );
  3         275756  
  3         41  
19 3     3   1319 use Types::Standard qw( InstanceOf ScalarRef HashRef Str );
  3         6  
  3         22  
20 3     3   5752 use Types::UUID qw( Uuid );
  3         117988  
  3         37  
21              
22             my $TrineNode = InstanceOf['RDF::Trine::Node::Resource'];
23             my $TrineNS = InstanceOf['RDF::Trine::Namespace'];
24             my $XmlNS = InstanceOf['XML::Namespace'];
25              
26             __PACKAGE__->meta->add_type({
27             name => Uri,
28             parent => InstanceOf[qw/ URI URI::WithBase /],
29             coercion => [
30             Uuid ,=> q{ "URI"->new("urn:uuid:$_") },
31             Str ,=> q{ "URI"->new($_) },
32             Path ,=> q{ "URI::file"->new($_) },
33             ScalarRef ,=> q{ do { my $u = "URI"->new("data:"); $u->data($$_); $u } },
34             HashRef ,=> q{ "URI"->new(URI::FromHash::uri(%$_)) },
35             $TrineNode ,=> q{ "URI"->new($_->uri_value) },
36             $TrineNS ,=> q{ "URI"->new($_->uri->uri_value) },
37             $XmlNS ,=> q{ "URI"->new($_->uri) },
38             ],
39             });
40              
41             __PACKAGE__->meta->add_type({
42             name => FileUri,
43             parent => Uri,
44             constraint => sub { $_->isa('URI::file') },
45             inlined => sub { InstanceOf->parameterize('URI::file')->inline_check($_[1]) },
46             coercion => [
47             Str ,=> q{ "URI::file"->new($_) },
48             Path ,=> q{ "URI::file"->new($_) },
49             HashRef ,=> q{ "URI"->new(URI::FromHash::uri(%$_)) },
50             $TrineNode ,=> q{ "URI"->new($_->uri_value) },
51             $TrineNS ,=> q{ "URI"->new($_->uri->uri_value) },
52             $XmlNS ,=> q{ "URI"->new($_->uri) },
53             ],
54             });
55              
56             __PACKAGE__->meta->add_type({
57             name => DataUri,
58             parent => Uri,
59             constraint => sub { $_->isa('URI::data') },
60             inlined => sub { InstanceOf->parameterize('URI::data')->inline_check($_[1]) },
61             coercion => [
62             Str ,=> q{ do { my $u = "URI"->new("data:"); $u->data($_); $u } },
63             ScalarRef ,=> q{ do { my $u = "URI"->new("data:"); $u->data($$_); $u } },
64             HashRef ,=> q{ "URI"->new(URI::FromHash::uri(%$_)) },
65             $TrineNode ,=> q{ "URI"->new($_->uri_value) },
66             $TrineNS ,=> q{ "URI"->new($_->uri->uri_value) },
67             $XmlNS ,=> q{ "URI"->new($_->uri) },
68             ],
69             });
70              
71             1;
72              
73             __END__
74              
75             =pod
76              
77             =encoding utf-8
78              
79             =head1 NAME
80              
81             Types::URI - type constraints and coercions for URIs
82              
83             =head1 SYNOPSIS
84              
85             package FroobleDocument;
86            
87             use Moose;
88             use Types::URI -all;
89            
90             has source => (
91             is => 'ro',
92             isa => Uri,
93             coerce => 1,
94             );
95              
96             =head1 DESCRIPTION
97              
98             L<Types::URI> is a type constraint library suitable for use with
99             L<Moo>/L<Moose> attributes, L<Kavorka> sub signatures, and so forth.
100              
101             =head2 Types
102              
103             This module provides some type constraints broadly compatible with
104             those provided by L<MooseX::Types::URI>, plus a couple of extra type
105             constraints.
106              
107             =over
108              
109             =item C<Uri>
110              
111             A class type for L<URI>/L<URI::WithBase>. Coercions from:
112              
113             =over
114              
115             =item from C<Uuid>
116              
117             Coerces to a URI in the C<< urn:uuid: >> schema. (See L<Types::UUID>.)
118              
119             =item from C<Str>
120              
121             Uses L<URI/new>.
122              
123             =item from C<Path>
124              
125             Uses L<URI::file/new>. (See L<Types::Path::Tiny>.)
126              
127             =item from C<ScalarRef>
128              
129             Uses L<URI::data/new>.
130              
131             =item from C<HashRef>
132              
133             Coerces using L<URI::FromHash>.
134              
135             =item from L<RDF::Trine::Node::Resource>, L<RDF::Trine::Namespace>, L<XML::Namespace>
136              
137             Uses L<URI/new>.
138              
139             =back
140              
141             =item C<FileUri>
142              
143             A subtype of C<Uri> covering L<URI::file>. Coercions from:
144              
145             =over
146              
147             =item from C<Str>
148              
149             Uses L<URI::file/new>.
150              
151             =item from C<Path>
152              
153             Uses L<URI::file/new>. (See L<Types::Path::Tiny>.)
154              
155             =item from C<HashRef>
156              
157             Coerces using L<URI::FromHash>.
158              
159             =item from L<RDF::Trine::Node::Resource>, L<RDF::Trine::Namespace>, L<XML::Namespace>
160              
161             Uses L<URI/new>.
162              
163             =back
164              
165             =item C<DataUri>
166              
167             A subtype of C<Uri> covering L<URI::data>. Coercions from:
168              
169             =over
170              
171             =item from C<Str>
172              
173             Uses L<URI::data/new>.
174              
175             =item from C<ScalarRef>
176              
177             Uses L<URI::data/new>.
178              
179             =item from C<HashRef>
180              
181             Coerces using L<URI::FromHash>.
182              
183             =item from L<RDF::Trine::Node::Resource>, L<RDF::Trine::Namespace>, L<XML::Namespace>
184              
185             Uses L<URI/new>.
186              
187             =back
188              
189             =back
190              
191             =head1 BUGS
192              
193             Please report any bugs to
194             L<http://rt.cpan.org/Dist/Display.html?Queue=Types-URI>.
195              
196             =head1 SEE ALSO
197              
198             L<MooseX::Types::URI>,
199             L<Type::Tiny::Manual>,
200             L<URI>,
201             L<URI::file>,
202             L<URI::data>,
203             L<URI::FromHash>,
204             L<RDF::Trine::Node::Resource>.
205              
206             L<Types::UUID>,
207             L<Types::Path::Tiny>,
208             L<Types::Standard>.
209              
210             =head1 AUTHOR
211              
212             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
213              
214             =head1 COPYRIGHT AND LICENCE
215              
216             This software is copyright (c) 2014 by Toby Inkster.
217              
218             This is free software; you can redistribute it and/or modify it under
219             the same terms as the Perl 5 programming language system itself.
220              
221             =head1 DISCLAIMER OF WARRANTIES
222              
223             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
224             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
225             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
226