Sitemap/XML/Types.pm

filter: Statementstmt 88.6% 78 / 88 Branchbran 60.0% 6 / 10 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 24 / 32 Podpod n/a totaltotal 76.5% 111 / 145 CC 11 SCAR 7.4
CC
11
Cov
81%
__ANON__
6.0
__ANON__
6.0
__ANON__
3.7
CRAP 2.1
« Sitemap/XML/Google/Image.pm ↑ Summary 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 22 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 $WWW::Sitemap::XML::Types::AUTHORITY = 'cpan:AJGB';
7 }
8 22 $WWW::Sitemap::XML::Types::VERSION = '2.02';
9 22 ▶use MooseX::Types -declare => [qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
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 )];
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 411 ▶ where {
Subroutine __ANON__: called CC=2 SCAR=6.9
41 411 my $url = to_Uri($_);
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 175 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 175 $_ eq lc($_)
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 4 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
64 4 length($_) <= 100
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 4 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 4 length($_) <= 2048
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 137 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
80 137 exists $valid_changefreqs{$_}
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 93 ▶ where {
Subroutine __ANON__: called CC=2 SCAR=6.9
91 93 ▶ $_ >= 0 && $_ <= 1
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 8 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
100 8 exists $valid_str_bool{ lc($_) }
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 0 ▶ via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
112 0 ▶ return WWW::Sitemap::XML::Google::Video->new( %{ $_ || {} } )
Condition0%0/2
$_ || {}
l!l
00
MC/DC0%0/1
$_ || {}
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
113 22 };
114  
115 22 subtype ArrayRefOfVideoObjects,
116 as ArrayRef[VideoObject];
117  
118 coerce ArrayRefOfVideoObjects,
119 from ArrayRef[HashRef|Object],
120 2 ▶ via {
Subroutine __ANON__: called CC=3 SCAR=11.7
121 [
122 2 ▶ map { blessed($_) ? $_ : WWW::Sitemap::XML::Google::Video->new( %{ $_ || {} } ) } @$_
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 0 2 2
Condition50%1/2
$_ || {}
l!l
20
MC/DC0%0/1
$_ || {}
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
123 ]
124 22 };
125  
126 22 role_type ImageObject, { role => 'WWW::Sitemap::XML::Google::Image::Interface' };
127  
128 coerce ImageObject,
129 from HashRef,
130 0 ▶ via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
131 0 ▶ return WWW::Sitemap::XML::Google::Image->new( %{ $_ || {} } )
Condition0%0/2
$_ || {}
l!l
00
MC/DC0%0/1
$_ || {}
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
132 22 };
133  
134 subtype ArrayRefOfImageObjects,
135 as ArrayRef[ImageObject],
136 2 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
137 2 scalar(@$_) <= 1000
138 22 };
139  
140 coerce ArrayRefOfImageObjects,
141 from ArrayRef[HashRef|Object],
142 2 ▶ via {
Subroutine __ANON__: called CC=3 SCAR=11.7
143 [
144 2 ▶ map { blessed($_) ? $_ : WWW::Sitemap::XML::Google::Image->new( %{ $_ || {} } ) } @$_
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 0 4 4
Condition50%1/2
$_ || {}
l!l
40
MC/DC0%0/1
$_ || {}
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
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 2 ▶ via {
Subroutine __ANON__: called CC=2 SCAR=7.2
154 2 ▶ WWW::Sitemap::XML::Google::Video::Player->new( %{ $_ || {} } )
Condition50%1/2
$_ || {}
l!l
20
MC/DC0%0/1
$_ || {}
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
155 22 };
156  
157 coerce VideoPlayer,
158 from Str,
159 0 ▶ via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
160 0 WWW::Sitemap::XML::Google::Video::Player->new( loc => $_ )
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__
« Sitemap/XML/Google/Image.pm ↑ Summary SitemapIndex/XML/Sitemap.pm »