File Coverage

blib/lib/DateTime/Fiction/JRRTolkien/Shire/Types.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 43 43 100.0


line stmt bran cond sub pod time code
1             package DateTime::Fiction::JRRTolkien::Shire::Types;
2              
3 9     9   168 use 5.008004;
  9         38  
4              
5 9     9   55 use strict;
  9         36  
  9         188  
6 9     9   44 use warnings;
  9         21  
  9         271  
7              
8 9     9   56 use parent qw{ Specio::Exporter };
  9         23  
  9         92  
9              
10 9     9   750 use Carp;
  9         21  
  9         792  
11 9         749 use Date::Tolkien::Shire::Data 0.001 qw{
12             __holiday_name_to_number
13             __month_name_to_number
14 9     9   803 };
  9         44663  
15 9     9   82 use Specio 0.18;
  9         185  
  9         240  
16 9     9   74 use Specio::Declare;
  9         19  
  9         220  
17 9     9   2279 use Specio::Library::Builtins;
  9         22  
  9         94  
18 9     9   88164 use Specio::Library::Numeric;
  9         37  
  9         76  
19 9     9   75644 use Specio::Library::String;
  9         34  
  9         79  
20              
21             our $VERSION = '0.905_01';
22              
23             declare(
24             DayOfMonth =>
25             parent => t( 'PositiveInt' ),
26             inline => sub {
27             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] <= 30";
28             },
29             );
30              
31             declare(
32             DayOfYear =>
33             parent => t( 'PositiveInt' ),
34             inline => sub {
35             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] <= 366";
36             },
37             );
38              
39             =begin comment
40              
41             object_isa_type(
42             Duration =>
43             class => 'DateTime::Fiction::JRRTolkien::Shire::Duration',
44             # class => 'DateTime::Duration',
45             );
46              
47             =end comment
48              
49             =cut
50              
51             # For some reason the above does not compile, though if you specify
52             # 'DateTime::Duration' it does. I believe the following to be
53             # equivalent, though I am sure it will produce a less-salubrious error
54             # message.
55              
56             declare(
57             Duration =>
58             parent => t( 'Object' ),
59             # inline => sub {
60             # $_[0]->parent->inline_check( $_[1] ) .
61             # " && $_[1]->isa( 'DateTime::Fiction::JRRTolkien::Shire::Duration' )";
62             # },
63             # For some reason the above is a problem under 5.8.9. So:
64             where => sub { $_[0]->isa(
65             'DateTime::Fiction::JRRTolkien::Shire::Duration' ) },
66             );
67              
68             enum(
69             EndOfMonthMode =>
70             values => [ qw{ limit preserve wrap } ],
71             );
72              
73             any_can_type(
74             Formatter =>
75             methods => [ qw{ format_datetime } ],
76             );
77              
78             declare(
79             HolidayName =>
80             parent => t( 'NonEmptySimpleStr' ),
81             where => sub { __holiday_name_to_number( $_[0] ) },
82             # Not the following, because the inline code gets evaluated in a Safe
83             # sandbox and I can not get access to the subroutine
84             # inline => sub {
85             # $_[0]->parent->inline_check( $_[1] ) .
86             # " && __holiday_name_to_number( $_[1] )";
87             # },
88             );
89              
90             declare(
91             HolidayNumber =>
92             parent => t( 'PositiveInt' ),
93             inline => sub {
94             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] <= 6";
95             },
96             );
97              
98             union(
99             Holiday =>
100             of => [ map { t( $_ ) } qw{ HolidayNumber HolidayName } ],
101             );
102              
103             declare(
104             Hour =>
105             parent => t( 'PositiveOrZeroInt' ),
106             inline => sub {
107             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] < 24";
108             },
109             );
110              
111             union(
112             IntOrUndef =>
113             of => [ map { t( $_ ) } qw{ Int Undef } ],
114             );
115              
116             declare(
117             LocaleObject =>
118             parent => t( 'Object' ),
119             inline => sub {
120             # Can't use $_[1] directly because 5.8 gives very weird errors
121             my $var = $_[1];
122             <<"EOF";
123             (
124             $var->isa('DateTime::Locale::FromData')
125             || $var->isa('DateTime::Locale::Base')
126             )
127             EOF
128             },
129             );
130              
131             union(
132             Locale =>
133             of => [ map { t( $_ ) } qw{ NonEmptySimpleStr LocaleObject } ],
134             );
135              
136             declare(
137             Minute =>
138             parent => t( 'PositiveOrZeroInt' ),
139             inline => sub {
140             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] < 60";
141             },
142             );
143              
144             declare(
145             MonthName =>
146             parent => t( 'NonEmptySimpleStr' ),
147             where => sub { __month_name_to_number( $_[0] ) },
148             # Not the following, because the inline code gets evaluated in a Safe
149             # sandbox and I can not get access to the subroutine
150             # inline => sub {
151             # $_[0]->parent->inline_check(#$_[1] ) .
152             # "#&& __month_name_to_number( $_[1] )";
153             # },
154             );
155              
156             declare(
157             MonthNumber =>
158             parent => t( 'PositiveInt' ),
159             inline => sub {
160             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] <= 12";
161             },
162             );
163              
164             union(
165             Month =>
166             of => [ map { t( $_ ) } qw{ MonthNumber MonthName } ],
167             );
168              
169             declare(
170             Nanosecond =>
171             parent => t( 'PositiveOrZeroInt' ),
172             );
173              
174             declare(
175             Second =>
176             parent => t( 'PositiveOrZeroInt' ),
177             inline => sub {
178             $_[0]->parent->inline_check( $_[1] ) . " && $_[1] < 62";
179             },
180             );
181              
182             object_can_type(
183             'TimeZoneObject',
184             methods => [
185             qw(
186             is_floating
187             is_utc
188             name
189             offset_for_datetime
190             short_name_for_datetime
191             )
192             ],
193             );
194              
195             declare(
196             'TimeZone',
197             of => [ map { t( $_ ) } qw{ NonEmptySimpleStr TimeZoneObject } ],
198             );
199              
200             enum(
201             TruncationLevel =>
202             values => [ qw{
203             year
204             quarter
205             month
206             week
207             local_week
208             day
209             hour
210             minute
211             second
212             nanosecond
213             } ],
214             );
215              
216             declare(
217             Year =>
218             parent => t( 'Int' ),
219             );
220              
221             1;
222              
223             __END__
224              
225             =head1 NAME
226              
227             DateTime::Fiction::JRRTolkien::Shire::Types - Specio types used for argument checking in DateTime::Fiction::JRRTolkien::Shire
228              
229             =head1 SYNOPSIS
230              
231             No user-serviceable parts inside.
232              
233             =head1 DESCRIPTION
234              
235             This Perl module is private to the
236             L<DateTime::Fiction::JRRTolkien::Shire|DateTime::Fiction::JRRTolkien::Shire>
237             distribution. It can be changed or revoked at any time.
238              
239             The purpose of this module is to provide L<Specio|Specio> argument type
240             definitions for
241             L<DateTime::Fiction::JRRTolkien::Shire|DateTime::Fiction::JRRTolkien::Shire>.
242              
243             =head1 SEE ALSO
244              
245             L<DateTime::Fiction::JRRTolkien::Shire|DateTime::Fiction::JRRTolkien::Shire>
246              
247             =head1 SUPPORT
248              
249             Support is by the author. Please file bug reports at
250             L<https://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Fiction-JRRTolkien-Shire>,
251             L<https://github.com/trwyant/perl-DateTime-Fiction-JRRTolkien-Shire/issues>, or in
252             electronic mail to the author.
253              
254             =head1 AUTHOR
255              
256             Thomas R. Wyant, III F<wyant at cpan dot org>
257              
258             =head1 COPYRIGHT AND LICENSE
259              
260             Copyright (C) 2017-2021 by Thomas R. Wyant, III
261              
262             This program is free software; you can redistribute it and/or modify it
263             under the same terms as Perl 5.10.0. For more details, see the full text
264             of the licenses in the directory LICENSES.
265              
266             This program is distributed in the hope that it will be useful, but
267             without any warranty; without even the implied warranty of
268             merchantability or fitness for a particular purpose.
269              
270             =cut
271              
272             # ex: set textwidth=72 :