line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::PMP::Profile::TypeConstraints; |
2
|
2
|
|
|
2
|
|
13
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
25
|
|
3
|
2
|
|
|
2
|
|
11412
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.102'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# The Net::PMP::Type::* prefix is used for all our type constraints |
8
|
|
|
|
|
|
|
# to avoid stepping on anyone's toes |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# locales |
11
|
2
|
|
|
2
|
|
4595
|
use Locale::Language; |
|
2
|
|
|
|
|
297084
|
|
|
2
|
|
|
|
|
318
|
|
12
|
|
|
|
|
|
|
my %all_langs = map { $_ => $_ } all_language_codes(); |
13
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::ISO6391' => as 'Str' => |
14
|
|
|
|
|
|
|
where { length($_) == 2 and exists $all_langs{$_} } => |
15
|
|
|
|
|
|
|
message {"The provided hreflang ($_) is not a valid ISO639-1 value."}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# datetimes |
18
|
2
|
|
|
2
|
|
792
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
881106
|
|
|
2
|
|
|
|
|
11
|
|
19
|
2
|
|
|
2
|
|
920
|
use DateTime::Format::DateParse; |
|
2
|
|
|
|
|
11227
|
|
|
2
|
|
|
|
|
512
|
|
20
|
|
|
|
|
|
|
my $coerce_datetime = sub { |
21
|
|
|
|
|
|
|
my $thing = shift; |
22
|
|
|
|
|
|
|
my $iso8601_formatter |
23
|
|
|
|
|
|
|
= DateTime::Format::Strptime->new( pattern => '%FT%T.%3NZ' ); |
24
|
|
|
|
|
|
|
if ( blessed $thing) { |
25
|
|
|
|
|
|
|
if ( $thing->isa('DateTime') ) { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# enforce UTC |
28
|
|
|
|
|
|
|
$thing->set_time_zone('UTC'); |
29
|
|
|
|
|
|
|
$thing->set_formatter($iso8601_formatter); |
30
|
|
|
|
|
|
|
return $thing; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
confess "$thing is not a DateTime object"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
|
|
|
|
|
|
my $dt = DateTime::Format::DateParse->parse_datetime($thing); |
36
|
|
|
|
|
|
|
if ( !$dt ) { |
37
|
|
|
|
|
|
|
confess "Invalid date format: $thing"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# enforce UTC |
41
|
|
|
|
|
|
|
$dt->set_time_zone('UTC'); |
42
|
|
|
|
|
|
|
$dt->set_formatter($iso8601_formatter); |
43
|
|
|
|
|
|
|
return $dt; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::DateTimeOrStr' => as class_type('DateTime'); |
47
|
|
|
|
|
|
|
coerce 'Net::PMP::Type::DateTimeOrStr' => from 'Object' => |
48
|
|
|
|
|
|
|
via { $coerce_datetime->($_) } => from 'Str' => |
49
|
|
|
|
|
|
|
via { $coerce_datetime->($_) }; |
50
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::ValidDates' => as |
51
|
|
|
|
|
|
|
'HashRef[Net::PMP::Type::DateTimeOrStr]'; |
52
|
|
|
|
|
|
|
coerce 'Net::PMP::Type::ValidDates' => from 'HashRef' => via { |
53
|
|
|
|
|
|
|
if ( !exists $_->{to} or !exists $_->{from} ) { |
54
|
|
|
|
|
|
|
confess "ValidDates must contain 'to' and 'from' keys"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
$_->{to} = $coerce_datetime->( $_->{to} ); |
57
|
|
|
|
|
|
|
$_->{from} = $coerce_datetime->( $_->{from} ); |
58
|
|
|
|
|
|
|
$_; |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Content types |
62
|
2
|
|
|
2
|
|
638
|
use Media::Type::Simple qw(is_type); |
|
2
|
|
|
|
|
10860
|
|
|
2
|
|
|
|
|
13
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#confess "MediaType defined!"; |
65
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::MediaType' => as 'Str' => where { |
66
|
|
|
|
|
|
|
is_type($_); |
67
|
|
|
|
|
|
|
} => message { |
68
|
|
|
|
|
|
|
"The value ($_) does not appear to be a valid media type."; |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# MediaEnclosure |
72
|
|
|
|
|
|
|
my $coerce_enclosure = sub { |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# defer till runtime to avoid circular dependency |
75
|
|
|
|
|
|
|
require Net::PMP::Profile::MediaEnclosure; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if ( ref( $_[0] ) eq 'HASH' ) { |
78
|
|
|
|
|
|
|
return Net::PMP::Profile::MediaEnclosure->new( $_[0] ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { return $_[0]; } |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::MediaEnclosure' => |
83
|
|
|
|
|
|
|
as class_type('Net::PMP::Profile::MediaEnclosure'); |
84
|
|
|
|
|
|
|
coerce 'Net::PMP::Type::MediaEnclosure' => from 'Any' => |
85
|
|
|
|
|
|
|
via { $coerce_enclosure->($_) }; |
86
|
|
|
|
|
|
|
subtype 'Net::PMP::Type::MediaEnclosures' => as |
87
|
|
|
|
|
|
|
'ArrayRef[Net::PMP::Type::MediaEnclosure]'; |
88
|
|
|
|
|
|
|
coerce 'Net::PMP::Type::MediaEnclosures' => from 'ArrayRef[HashRef]' => via { |
89
|
|
|
|
|
|
|
[ map { $coerce_enclosure->($_) } @$_ ]; |
90
|
|
|
|
|
|
|
} => from 'HashRef' => via { [ $coerce_enclosure->($_) ] }; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
2
|
|
610
|
no Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
27
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Net::PMP::Profile::TypeConstraints - enforce attribute values |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
package My::Class; |
107
|
|
|
|
|
|
|
use Moose; |
108
|
|
|
|
|
|
|
use Net::PMP::Profile::TypeConstraints; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# provide validation checking |
111
|
|
|
|
|
|
|
has 'uri' => (isa => 'Net::PMP::Type::Href'); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Net::PMP::Profile::TypeConstraints defines validation constraints for Net::PMP classes. |
118
|
|
|
|
|
|
|
This is a utility class defining types with L<Moose::Util::TypeConstraints> |
119
|
|
|
|
|
|
|
in the C<Net::PMP::Type> namespace. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Peter Karman, C<< <karman at cpan.org> >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 BUGS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-net-pmp at rt.cpan.org>, or through |
128
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-PMP-Profile>. I will be notified, and then you'll |
129
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SUPPORT |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
perldoc Net::PMP::CollectionDoc::Link |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
You can also look for information at: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=over 4 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item RT: CPAN's request tracker (report bugs here) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-PMP-Profile> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item AnnoCPAN: Annotated CPAN documentation |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Net-PMP-Profile> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item CPAN Ratings |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Net-PMP-Profile> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item Search CPAN |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Net-PMP-Profile/> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
American Public Media and the Public Media Platform sponsored the development of this module. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright 2013 American Public Media Group |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
See the LICENSE file that accompanies this module. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|