blib/lib/WWW/Sitemap/XML/Types.pm

filter: Statementstmt 88.6% 78 / 88 Branchbran 45.0% 9 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 24 / 32 Podpod n/a totaltotal 79.2% 111 / 140 CC 11 SCAR 7.4
CC
11
Cov
81%
__ANON__
6.0
__ANON__
6.0
__ANON__
3.7
CRAP 2.1
« Build ↑ Summary blib/lib/WWW/SitemapIndex/XML/Sitemap.pm »
1 #ABSTRACT: Type constraints used by WWW::Sitemap::XML and WWW::Sitemap::XML::URL
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package WWW::Sitemap::XML::Types;
5 BEGIN {
6 22 ▶ $WWW::Sitemap::XML::Types::AUTHORITY = 'cpan:AJGB';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 }
8 22 $WWW::Sitemap::XML::Types::VERSION = '2.01';
9 22 use MooseX::Types -declare => [qw(
10 SitemapURL
11 SitemapIndexSitemap
12  
13 Location
14 ChangeFreq
15 LowercaseStr
16 Priority
17  
18 VideoPlayer
19 VideoObject
20 ArrayRefOfVideoObjects
21 ImageObject
22 ArrayRefOfImageObjects
23 StrBool
24 Max100CharsStr
25 Max2048CharsStr
26 22 ▶)];
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 22 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 22 ▶use MooseX::Types::Moose qw( Object Str Num Bool ArrayRef HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 22 ▶use MooseX::Types::URI qw( Uri );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 22 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 22 role_type SitemapURL, { role => 'WWW::Sitemap::XML::URL::Interface' };
34  
35 22 role_type SitemapIndexSitemap, { role => 'WWW::SitemapIndex::XML::Sitemap::Interface' };
36  
37 # <loc>
38 subtype Location,
39 as Str,
40 where {
41 411 ▶ my $url = to_Uri($_);
Subroutine __ANON__: called CC=2 SCAR=6.9
42 411 ▶ $url->scheme && $url->authority
Branch: 1 branch
BranchTrueFalseTotal
$url->scheme and $url->authority 405 6 411
43 },
44 5 ▶ message { "$_ is not a valid URL" };
Subroutine __ANON__: called CC=1 SCAR=0.0
45  
46 coerce Location,
47 from Uri,
48 3 ▶ via { $_->as_string };
Subroutine __ANON__: called CC=1 SCAR=0.0
49  
50 subtype LowercaseStr,
51 as Str,
52 where {
53 175 ▶ $_ eq lc($_)
Subroutine __ANON__: called CC=1 SCAR=0.0
54 },
55 0 ▶ message { "$_ contains uppercase characters" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
56  
57 coerce LowercaseStr,
58 from Str,
59 0 ▶ via { lc($_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
60  
61 subtype Max100CharsStr,
62 as Str,
63 where {
64 4 ▶ length($_) <= 100
Subroutine __ANON__: called CC=1 SCAR=0.0
65 },
66 0 ▶ message { "Maximum of 100 characters allowed" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
67  
68 subtype Max2048CharsStr,
69 as Str,
70 where {
71 4 ▶ length($_) <= 2048
Subroutine __ANON__: called CC=1 SCAR=0.0
72 },
73 0 ▶ message { "Maximum of 2048 characters allowed" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
74  
75 # <changefreq>
76 22 my %valid_changefreqs = map { $_ => 1 } qw( always hourly daily weekly monthly yearly never );
77 subtype ChangeFreq,
78 as LowercaseStr,
79 where {
80 137 ▶ exists $valid_changefreqs{$_}
Subroutine __ANON__: called CC=1 SCAR=0.0
81 22 };
82  
83 coerce ChangeFreq,
84 from Str,
85 31 ▶ via { lc($_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
86  
87 # <priority>
88 subtype Priority,
89 as Num,
90 where {
91 93 ▶ $_ >= 0 && $_ <= 1
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ <= 1 92 1 93
92 },
93 4 ▶ message { 'Valid priority ranges from 0.0 to 1.0'};
Subroutine __ANON__: called CC=1 SCAR=0.0
94  
95 # allow_embed
96 22 my %valid_str_bool = ( yes => 1, no => 1 );
97 subtype StrBool,
98 as LowercaseStr,
99 where {
100 8 ▶ exists $valid_str_bool{ lc($_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
101 22 };
102  
103 coerce StrBool,
104 from Bool,
105 0 ▶ via { $_ ? 'yes' : 'no' };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
106  
107 22 role_type VideoObject, { role => 'WWW::Sitemap::XML::Google::Video::Interface' };
108  
109 coerce VideoObject,
110 from HashRef,
111 via {
112 0 ▶ return WWW::Sitemap::XML::Google::Video->new( %{ $_ || {} } )
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ or {} 0 0 0
113 22 };
114  
115 22 subtype ArrayRefOfVideoObjects,
116 as ArrayRef[VideoObject];
117  
118 coerce ArrayRefOfVideoObjects,
119 from ArrayRef[HashRef|Object],
120 via {
121 [
122 2 ▶ map { blessed($_) ? $_ : WWW::Sitemap::XML::Google::Video->new( %{ $_ || {} } ) } @$_
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($_) ? : 0 2 2
$_ or {} 0 2 2
123 ]
124 22 };
125  
126 22 role_type ImageObject, { role => 'WWW::Sitemap::XML::Google::Image::Interface' };
127  
128 coerce ImageObject,
129 from HashRef,
130 via {
131 0 ▶ return WWW::Sitemap::XML::Google::Image->new( %{ $_ || {} } )
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ or {} 0 0 0
132 22 };
133  
134 subtype ArrayRefOfImageObjects,
135 as ArrayRef[ImageObject],
136 where {
137 2 ▶ scalar(@$_) <= 1000
Subroutine __ANON__: called CC=1 SCAR=0.0
138 22 };
139  
140 coerce ArrayRefOfImageObjects,
141 from ArrayRef[HashRef|Object],
142 via {
143 [
144 2 ▶ map { blessed($_) ? $_ : WWW::Sitemap::XML::Google::Image->new( %{ $_ || {} } ) } @$_
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($_) ? : 0 4 4
$_ or {} 0 4 4
145 ]
146 22 };
147  
148  
149 22 role_type VideoPlayer, { role => 'WWW::Sitemap::XML::Google::Video::Player::Interface' };
150  
151 coerce VideoPlayer,
152 from HashRef,
153 via {
154 2 ▶ WWW::Sitemap::XML::Google::Video::Player->new( %{ $_ || {} } )
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$_ or {} 0 2 2
155 22 };
156  
157 coerce VideoPlayer,
158 from Str,
159 via {
160 0 ▶ WWW::Sitemap::XML::Google::Video::Player->new( loc => $_ )
Subroutine __ANON__: not called CC=1 SCAR=6.9
161 22 };
162  
163 # runtime to avoid circular references
164 22 require WWW::Sitemap::XML::Google::Image;
165 22 require WWW::Sitemap::XML::Google::Video;
166 22 require WWW::Sitemap::XML::Google::Video::Player;
167  
168  
169 22 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
170  
171 22 1;
172  
173 __END__
174  
175 =pod
176  
177 =encoding UTF-8
178  
179 =head1 NAME
180  
181 WWW::Sitemap::XML::Types - Type constraints used by WWW::Sitemap::XML and WWW::Sitemap::XML::URL
182  
183 =head1 VERSION
184  
185 version 2.01
186  
187 =head1 DESCRIPTION
188  
189 Type constraints used by L<WWW::Sitemap::XML> and L<WWW::Sitemap::XML::URL>.
190  
191 =head1 TYPES
192  
193 =head2 Location
194  
195 has 'loc' => (
196 is => 'rw',
197 isa => Location,
198 );
199  
200 URL location, coerced from L<Uri|MooseX::Types::URI> via C<{ $_-E<gt>as_string }>.
201  
202 =head2 ChangeFreq
203  
204 has 'changefreq' => (
205 is => 'rw',
206 isa => ChangeFreq,
207 );
208  
209 Valid values are:
210  
211 =over
212  
213 =item * always
214  
215 =item * hourly
216  
217 =item * daily
218  
219 =item * weekly
220  
221 =item * monthly
222  
223 =item * yearly
224  
225 =item * never
226  
227 =back
228  
229 =head2 Priority
230  
231 has 'priority' => (
232 is => 'rw',
233 isa => Priority,
234 );
235  
236 Subtype of C<Num> with values in range from C<0.0> to C<1.0>.
237  
238 =head2 SitemapURL
239  
240 has 'url' => (
241 is => 'rw',
242 isa => SitemapURL,
243 );
244  
245 Role type, argument needs to implement L<WWW::Sitemap::XML::URL::Interface>.
246  
247 =head2 SitemapIndexSitemap
248  
249 has 'sitemap' => (
250 is => 'rw',
251 isa => SitemapIndexSitemap,
252 );
253  
254 Role type, argument needs to implement L<WWW::SitemapIndex::XML::Sitemap::Interface>.
255  
256 =head2 LowercaseStr
257  
258 has 'lowercase' => (
259 is => 'rw',
260 coerce => 1,
261 isa => LowercaseStr,
262 );
263  
264 Subtype of C<Str>, with only lowercase characters.
265  
266 Coerces from C<Str> using C<lc>.
267  
268 =head2 Max100CharsStr
269  
270 has 'short_str' => (
271 is => 'rw',
272 isa => Max100CharsStr,
273 );
274  
275 Subtype of C<Str>, up to 100 characters.
276  
277 =head2 Max2048CharsStr
278  
279 has 'longer_str' => (
280 is => 'rw',
281 isa => Max2048CharsStr,
282 );
283  
284 Subtype of C<Str>, up to 2048 characters.
285  
286 =head2 StrBool
287  
288 has 'yes_no' => (
289 is => 'rw',
290 coerce => 1,
291 isa => StrBool,
292 );
293  
294 Subtype of C<LowercaseStr>, with valid values I<yes> and I<no>.
295  
296 Coerces from C<Bool>.
297  
298 =head2 ImageObject
299  
300 has 'image' => (
301 is => 'rw',
302 coerce => 1,
303 isa => ImageObject,
304 );
305  
306 Role type, argument needs to implement L<WWW::Sitemap::XML::Google::Image::Interface>.
307  
308 Coerces from C<HashRef> by creating L<WWW::Sitemap::XML::Google::Image> object.
309  
310 =head2 ArrayRefOfImageObjects
311  
312 has 'images' => (
313 is => 'rw',
314 coerce => 1,
315 isa => ArrayRefOfImageObjects,
316 );
317  
318 Subtype of C<ArrayRef>, were values are L<"ImageObject"> elements.
319  
320 Coerces from C<ArrayRef[HashRef]> by creating an array of L<WWW::Sitemap::XML::Google::Image> objects.
321  
322 =head2 VideoObject
323  
324 has 'video' => (
325 is => 'rw',
326 coerce => 1,
327 isa => VideoObject,
328 );
329  
330 Role type, argument needs to implement L<WWW::Sitemap::XML::Google::Video::Interface>.
331  
332 Coerces from C<HashRef> by creating L<WWW::Sitemap::XML::Google::Video> object.
333  
334 =head2 ArrayRefOfVideoObjects
335  
336 has 'videos' => (
337 is => 'rw',
338 coerce => 1,
339 isa => ArrayRefOfVideoObjects,
340 );
341  
342 Subtype of C<ArrayRef>, were values are L<"VideoObject"> elements.
343  
344 Coerces from C<ArrayRef[HashRef]> by creating an array of L<WWW::Sitemap::XML::Google::Video> objects.
345  
346 =head2 VideoPlayer
347  
348 has 'video_player' => (
349 is => 'rw',
350 coerce => 1,
351 isa => VideoPlayer,
352 );
353  
354 Role type, argument needs to implement L<WWW::Sitemap::XML::Google::Video::Player::Interface>.
355  
356 Coerces from C<HashRef> by creating L<WWW::Sitemap::XML::Google::Video::Player> object.
357  
358 Coerces from C<Str> by creating L<WWW::Sitemap::XML::Google::Video::Player>
359 object, where the string is used as L<WWW::Sitemap::XML::Google::Video::Player/"loc">.
360  
361 =head1 AUTHOR
362  
363 Alex J. G. Burzyński <ajgb@cpan.org>
364  
365 =head1 COPYRIGHT AND LICENSE
366  
367 This software is copyright (c) 2014 by Alex J. G. Burzyński <ajgb@cpan.org>.
368  
369 This is free software; you can redistribute it and/or modify it under
370 the same terms as the Perl 5 programming language system itself.
371  
372 =cut
« Build ↑ Summary blib/lib/WWW/SitemapIndex/XML/Sitemap.pm »