lib/MouseX/Types/URI.pm

filter: Statementstmt 70.6% 53 / 75 Branchbran 33.3% 2 / 6 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 50.0% 14 / 28 Podpod n/a totaltotal 66.1% 78 / 118 CC 5 SCAR 7.8
CC
5
Cov
70%
__ANON__
6.0
__ANON__
6.0
__ANON__
3.0
CRAP 2.2
↑ Summary
1 package MouseX::Types::URI;
2  
3 2 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use URI::data;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use URI::WithBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use URI::FromHash ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use MouseX::Types -declare => [qw(Uri FileUri DataUri)]; # export types
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use MouseX::Types::Mouse qw(Str ScalarRef HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use MouseX::Types::Path::Class qw(File Dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our $VERSION = '0.03';
18  
19 type 'URI', # doesn't use class_type 'URI'
20 19 ▶ where { Scalar::Util::blessed($_) and ($_->isa('URI') or $_->isa('URI::WithBase')) };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->isa("URI") || $_->isa("URI::WithBase") 17 2 19
Condition100%6/6
builtin::blessed($_) && ($_->isa('URI') || $_->isa('URI::WithBase'))
!ll&&!rl&&r
2116
$_->isa("URI") or $_->isa("URI::WithBase")
l!l&&r!l&&!r
1061
MC/DC100%3/3
builtin::blessed($_) && ($_->isa('URI') || $_->isa('URI::WithBase'))
builtin::blessed($_) $_->isa("URI") $_->isa("URI::WithBase")
Truth table100%4/4
A && B or C
A= builtin::blessed($_)B= $_->isa("URI")C= $_->isa("URI::WithBase")
ABCresult
0XX0
1000
11X1
1011
21  
22 2 class_type 'URI::file';
23 2 class_type 'URI::data';
24  
25 2 subtype Uri, as 'URI';
26 2 subtype FileUri, as 'URI::file';
27 2 subtype DataUri, as 'URI::data';
28  
29 2 for my $type ( 'URI', Uri ) {
30 coerce($type,
31 0 ▶ from Str, via { URI->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 ▶ from ScalarRef, via { my $u = URI->new('data:'); $u->data($$_); $u },
Subroutine __ANON__: not called CC=1 SCAR=6.9
33 0 ▶ from HashRef, via { URI::FromHash::uri(%$_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ from File, via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ from Dir, via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ▶ from 'Path::Class::Dir', via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 ▶ from 'Path::Class::File', via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 4 );
39 }
40  
41 2 for my $type ( 'URI::file', FileUri ) {
42 coerce($type,
43 0 ▶ from Str, via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 ▶ from File, via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 ▶ from Dir, via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 ▶ from 'Path::Class::Dir', via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 ▶ from 'Path::Class::File', via { URI::file->new($_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 4 );
49 }
50  
51 2 for my $type ( 'URI::data', DataUri ) {
52 coerce($type,
53 0 ▶ from Str, via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
54 0 ▶ /^data:/ ? URI->new($_) : do { my $u = URI->new('data:'); $u->data($_); $u }
Branch: 1 branch
BranchTrueFalseTotal
/^data:/ ? : 0 0 0
55 },
56 0 ▶ from ScalarRef, via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
57 0 ▶ $$_ =~ /^data:/ ? URI->new($$_) : do { my $u = URI->new('data:'); $u->data($$_); $u }
Branch: 1 branch
BranchTrueFalseTotal
$$_ =~ /^data:/ ? : 0 0 0
58 },
59 4 );
60 }
61  
62 2 1;
63  
64 =head1 NAME
65  
66 MouseX::Types::URI - A URI type library for Mouse
67  
68 =head1 SYNOPSIS
69  
70 =head2 CLASS TYPES
71  
72 package MyApp;
73 use Mouse;
74 use MouseX::Types::URI;
75  
76 has 'uri' => (
77 is => 'rw',
78 isa => 'URI',
79 coerce => 1,
80 );
81  
82 has 'data' => (
83 is => 'rw',
84 isa => 'URI::data',
85 coerce => 1,
86 );
87  
88 has 'file' => (
89 is => 'rw',
90 isa => 'URI::file',
91 coerce => 1,
92 );
93  
94 =head2 CUSTOM TYPES
95  
96 package MyApp;
97 use Mouse;
98 use MouseX::Types::URI qw(Uri DataUri FileUri);
99  
100 has 'uri' => (
101 is => 'rw',
102 isa => Uri,
103 coerce => 1,
104 );
105  
106 has 'data' => (
107 is => 'rw',
108 isa => DataUri,
109 coerce => 1,
110 );
111  
112 has 'file' => (
113 is => 'rw',
114 isa => FileUri,
115 coerce => 1,
116 );
117  
118 =head1 DESCRIPTION
119  
120 MouseX::Types::URI creates common L<Mouse> types,
121 coercions and option specifications useful for dealing
122 with L<URI>s as L<Mouse> attributes.
123  
124 Coercions (see L<Mouse::Util::TypeConstraints>) are made from
125 C<Str>, C<ScalarRef>, C<HashRef>,
126 L<Path::Class::Dir> and L<Path::Class::File> to
127 L<URI>, L<URI::data> and L<URI::file> objects.
128  
129 =head1 TYPES
130  
131 =head2 Uri
132  
133 =over 4
134  
135 Either L<URI> or L<URI::WithBase>.
136  
137 Coerces from C<Str> via L<URI/new>.
138  
139 Coerces from L<Path::Class::File> and L<Path::Class::Dir> via L<URI::file/new>.
140  
141 Coerces from C<ScalarRef> via L<URI::data/new>.
142  
143 Coerces from C<HashRef> using L<URI::FromHash>.
144  
145 =back
146  
147 =head2 DataUri
148  
149 =over 4
150  
151 A URI whose scheme is C<data>.
152  
153 Coerces from C<Str> and C<ScalarRef> via L<URI::data/new>.
154  
155 =back
156  
157 =head2 FileUri
158  
159 =over 4
160  
161 A L<URI::file> class type.
162  
163 Coerces from C<Str>, L<Path::Class::File> and L<Path::Class::Dir> via L<URI::file/new>
164  
165 =back
166  
167 =head1 AUTHOR
168  
169 NAKAGAWA Masaki E<lt>masaki@cpan.orgE<gt>
170  
171 =head1 THANKS TO
172  
173 Yuval Kogman, L<MooseX::Types::URI/AUTHOR>
174  
175 =head1 LICENSE
176  
177 This library is free software; you can redistribute it and/or modify
178 it under the same terms as Perl itself.
179  
180 =head1 SEE ALSO
181  
182 L<Mouse>, L<MouseX::Types>,
183  
184 L<URI>, L<URI::data>, L<URI::file>, L<URI::WithBase>, L<URI::FromHash>,
185  
186 L<MooseX::Types::URI>
187  
188 =cut
↑ Summary